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

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

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

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

d = A("d")
l = B("l")
b = C("b")
a = D("a")
i = C("i")

d.z = a
l.q = d
l.u = d
l.o = i
l.z = i
b.o = i
b.x = i
a.t = d
i.o = b
i.x = b
assert l.z.x.x.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

d = A("d")
l = B("l")
b = C("b")
a = D("a")
i = C("i")

d.z = a
l.q = d
l.u = d
l.o = i
l.z = i
b.o = i
b.x = i
a.t = d
i.o = b
i.x = b
assert l.z.x.x.x.o.txt == "i"