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

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

h = A("h")
d = B("d")
i = B("i")
k = A("k")
g = B("g")
m = B("m")
j = A("j")
a = A("a")
n = B("n")

h.u = a
d.t = g
d.u = h
i.t = n
i.u = j
k.u = j
g.t = i
g.u = a
m.t = d
m.u = h
j.u = k
a.u = j
n.t = i
n.u = h
assert n.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.t: B = None
        self.u: A = None
        self.txt = txt

h = A("h")
d = B("d")
i = B("i")
k = A("k")
g = B("g")
m = B("m")
j = A("j")
a = A("a")
n = B("n")

h.u = a
d.t = g
d.u = h
i.t = n
i.u = j
k.u = j
g.t = i
g.u = a
m.t = d
m.u = h
j.u = k
a.u = j
n.t = i
n.u = h
assert n.u.u.u.u.u.u.u.txt == "j"