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

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

b = A("b")
m = B("m")
d = A("d")
k = B("k")

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

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

b = A("b")
m = B("m")
d = A("d")
k = B("k")

b.o = d
b.t = m
m.u = k
d.o = b
d.t = m
k.u = m
assert k.u.u.u.u.txt == "k"