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

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

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

b.u = n
j.p = a
d.p = a
f.u = i
n.u = i
k.p = a
a.p = k
l.p = d
i.u = f
assert b.u.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.p: B = None
        self.txt = txt

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

b.u = n
j.p = a
d.p = a
f.u = i
n.u = i
k.p = a
a.p = k
l.p = d
i.u = f
assert b.u.u.u.u.u.txt == "f"