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

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

g = A("g")
f = B("f")
m = B("m")
d = B("d")
a = A("a")
i = A("i")
b = A("b")
e = A("e")

g.u = f
f.t = d
m.t = f
d.t = m
a.u = f
i.u = d
b.u = m
e.u = m
assert f.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
m = B("m")
d = B("d")
a = A("a")
i = A("i")
b = A("b")
e = A("e")

g.u = f
f.t = d
m.t = f
d.t = m
a.u = f
i.u = d
b.u = m
e.u = m
assert f.t.t.t.txt == "f"