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

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

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

m = A("m")
i = B("i")
a = C("a")
d = C("d")
j = C("j")

m.q = j
i.u = m
a.q = m
a.t = i
a.z = i
d.q = m
d.t = i
d.z = i
j.q = m
j.t = i
j.z = i
assert d.q.q.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

m = A("m")
i = B("i")
a = C("a")
d = C("d")
j = C("j")

m.q = j
i.u = m
a.q = m
a.t = i
a.z = i
d.q = m
d.t = i
d.z = i
j.q = m
j.t = i
j.z = i
assert d.q.q.z.u.txt == "m"