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

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

l = A("l")
a = B("a")
e = B("e")
f = A("f")
m = B("m")
i = A("i")
b = B("b")
k = A("k")
g = B("g")
h = A("h")

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

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

l = A("l")
a = B("a")
e = B("e")
f = A("f")
m = B("m")
i = A("i")
b = B("b")
k = A("k")
g = B("g")
h = A("h")

l.q = m
a.y = k
e.y = i
f.q = b
m.y = h
i.q = b
b.y = k
k.q = m
g.y = i
h.q = a
assert b.y.q.y.q.y.q.y.q.y.q.txt == "m"