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

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

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

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

f = A("f")
k = B("k")
d = C("d")
e = D("e")
b = B("b")

f.z = d
f.x = e
k.w = b
k.q = b
d.o = f
d.q = b
e.x = b
b.w = k
b.q = k
assert d.q.q.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: D = None
        self.txt = txt

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

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

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

f = A("f")
k = B("k")
d = C("d")
e = D("e")
b = B("b")

f.z = d
f.x = e
k.w = b
k.q = b
d.o = f
d.q = b
e.x = b
b.w = k
b.q = k
assert d.q.q.q.w.txt == "k"