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

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

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

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

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

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

f.x = e
m.u = f
m.t = i
e.u = g
e.t = n
b.x = e
i.u = b
i.t = e
d.x = m
g.x = n
n.u = b
n.t = e
j.u = f
j.t = e
assert j.t.t.t.t.txt == "n"