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

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

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

b = A("b")
m = B("m")
n = C("n")
j = C("j")
c = A("c")

b.z = m
m.t = b
n.q = m
j.q = m
c.z = m
assert m.t.z.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

b = A("b")
m = B("m")
n = C("n")
j = C("j")
c = A("c")

b.z = m
m.t = b
n.q = m
j.q = m
c.z = m
assert m.t.z.t.z.txt == "m"