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.txt = txt

b = A("b")
d = B("d")
c = B("c")
m = A("m")
f = B("f")
e = A("e")

b.o = c
d.u = b
c.u = b
m.o = d
f.u = m
e.o = d
assert d.u.o.u.o.u.o.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.txt = txt

b = A("b")
d = B("d")
c = B("c")
m = A("m")
f = B("f")
e = A("e")

b.o = c
d.u = b
c.u = b
m.o = d
f.u = m
e.o = d
assert d.u.o.u.o.u.o.txt == "c"