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

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

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

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

n = A("n")
d = B("d")
k = C("k")
f = D("f")
g = B("g")
m = C("m")

n.o = m
d.z = n
k.o = n
k.u = m
f.q = n
f.r = m
g.z = n
m.o = n
m.u = k
assert k.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

n = A("n")
d = B("d")
k = C("k")
f = D("f")
g = B("g")
m = C("m")

n.o = m
d.z = n
k.o = n
k.u = m
f.q = n
f.r = m
g.z = n
m.o = n
m.u = k
assert k.o.o.o.txt == "n"