class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.t: B = None
        self.r: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

i = A("i")
f = B("f")
n = C("n")
c = B("c")
m = C("m")

i.x = c
f.y = i
f.t = c
f.r = n
n.q = i
c.y = i
c.t = f
c.r = m
m.q = i
assert n.q.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.t: B = None
        self.r: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

i = A("i")
f = B("f")
n = C("n")
c = B("c")
m = C("m")

i.x = c
f.y = i
f.t = c
f.r = n
n.q = i
c.y = i
c.t = f
c.r = m
m.q = i
assert n.q.x.y.txt == "i"