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

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

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

m.u = g
m.t = n
n.q = k
k.q = b
j.u = n
j.t = k
a.u = g
a.t = k
d.u = g
d.t = b
b.q = k
f.u = b
f.t = b
i.u = g
i.t = k
g.q = b
assert n.q.q.q.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.t: B = None
        self.txt = txt

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

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

m.u = g
m.t = n
n.q = k
k.q = b
j.u = n
j.t = k
a.u = g
a.t = k
d.u = g
d.t = b
b.q = k
f.u = b
f.t = b
i.u = g
i.t = k
g.q = b
assert n.q.q.q.q.q.q.q.q.q.q.txt == "b"