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

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

m = A("m")
f = B("f")
n = B("n")
b = B("b")
d = A("d")
a = A("a")
k = A("k")
e = B("e")

m.o = a
f.t = e
n.t = e
b.t = e
d.o = k
a.o = m
k.o = m
e.t = n
assert m.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

m = A("m")
f = B("f")
n = B("n")
b = B("b")
d = A("d")
a = A("a")
k = A("k")
e = B("e")

m.o = a
f.t = e
n.t = e
b.t = e
d.o = k
a.o = m
k.o = m
e.t = n
assert m.o.o.o.o.txt == "m"