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

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

h = A("h")
l = B("l")
d = A("d")
c = A("c")
e = B("e")
f = A("f")
i = A("i")
k = B("k")
b = B("b")
a = A("a")

h.y = c
l.u = k
d.y = h
c.y = i
e.u = l
f.y = d
i.y = h
k.u = l
b.u = k
a.y = i
assert b.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

h = A("h")
l = B("l")
d = A("d")
c = A("c")
e = B("e")
f = A("f")
i = A("i")
k = B("k")
b = B("b")
a = A("a")

h.y = c
l.u = k
d.y = h
c.y = i
e.u = l
f.y = d
i.y = h
k.u = l
b.u = k
a.y = i
assert b.u.u.u.u.u.txt == "k"