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

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

l = A("l")
b = B("b")
i = A("i")
f = B("f")
n = B("n")
d = A("d")
g = B("g")
a = A("a")

l.u = i
b.x = l
i.u = d
f.x = l
n.x = l
d.u = a
g.x = a
a.u = i
assert i.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

l = A("l")
b = B("b")
i = A("i")
f = B("f")
n = B("n")
d = A("d")
g = B("g")
a = A("a")

l.u = i
b.x = l
i.u = d
f.x = l
n.x = l
d.u = a
g.x = a
a.u = i
assert i.u.u.u.u.txt == "d"