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

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

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

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

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

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