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

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

d = A("d")
h = B("h")
c = B("c")
f = B("f")
l = A("l")
j = A("j")
b = B("b")
a = A("a")

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

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

d = A("d")
h = B("h")
c = B("c")
f = B("f")
l = A("l")
j = A("j")
b = B("b")
a = A("a")

d.u = l
d.t = h
h.y = f
c.y = f
f.y = b
l.u = j
l.t = f
j.u = d
j.t = b
b.y = c
a.u = j
a.t = f
assert b.y.y.y.y.y.txt == "f"