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

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

a = A("a")
d = B("d")
b = A("b")
l = B("l")
m = B("m")

a.o = b
d.u = l
b.o = a
l.u = m
m.u = d
assert m.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

a = A("a")
d = B("d")
b = A("b")
l = B("l")
m = B("m")

a.o = b
d.u = l
b.o = a
l.u = m
m.u = d
assert m.u.u.u.u.u.txt == "l"