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

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

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

class D:
    def __init__(self, txt: str):
        self.t: C = None
        self.o: A = None
        self.txt = txt

m = A("m")
c = B("c")
e = C("e")
a = D("a")
b = C("b")

m.q = a
c.z = e
c.o = m
e.t = b
a.t = b
a.o = m
b.t = e
assert m.q.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.t: C = None
        self.o: A = None
        self.txt = txt

m = A("m")
c = B("c")
e = C("e")
a = D("a")
b = C("b")

m.q = a
c.z = e
c.o = m
e.t = b
a.t = b
a.o = m
b.t = e
assert m.q.t.t.t.t.txt == "e"