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

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

m = A("m")
j = B("j")
i = B("i")
c = A("c")
k = B("k")
b = B("b")
l = B("l")
e = A("e")
a = A("a")

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

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

m = A("m")
j = B("j")
i = B("i")
c = A("c")
k = B("k")
b = B("b")
l = B("l")
e = A("e")
a = A("a")

m.q = b
j.y = b
i.y = l
c.q = k
k.y = i
b.y = j
l.y = j
e.q = l
a.q = j
assert b.y.y.y.y.y.y.y.y.y.txt == "j"