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

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

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

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

j = A("j")
m = B("m")
c = C("c")
d = D("d")

j.o = c
j.z = m
m.u = j
c.o = d
d.p = m
assert d.p.u.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.z: B = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
c = C("c")
d = D("d")

j.o = c
j.z = m
m.u = j
c.o = d
d.p = m
assert d.p.u.o.o.txt == "d"