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

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

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

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

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

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

k.y = j
h.q = j
c.y = b
e.q = a
m.y = b
j.q = a
b.q = e
f.y = a
a.q = h
n.y = a
assert k.y.q.q.q.q.q.txt == "h"