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

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

n = A("n")
a = B("a")
j = A("j")
e = B("e")
i = B("i")
k = B("k")
b = B("b")
m = B("m")
h = B("h")

n.u = j
a.q = m
j.u = n
e.q = m
i.q = b
k.q = b
b.q = i
m.q = a
h.q = b
assert k.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

n = A("n")
a = B("a")
j = A("j")
e = B("e")
i = B("i")
k = B("k")
b = B("b")
m = B("m")
h = B("h")

n.u = j
a.q = m
j.u = n
e.q = m
i.q = b
k.q = b
b.q = i
m.q = a
h.q = b
assert k.q.q.q.q.q.q.txt == "i"