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

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

m = A("m")
b = B("b")
j = A("j")
d = B("d")
e = A("e")

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

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

m = A("m")
b = B("b")
j = A("j")
d = B("d")
e = A("e")

m.o = b
b.u = e
b.z = d
j.o = b
d.u = m
d.z = b
e.o = d
assert d.u.o.z.txt == "d"