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

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

i = A("i")
g = B("g")
a = B("a")
l = B("l")
n = A("n")
k = B("k")
b = A("b")
d = A("d")
e = A("e")
m = A("m")

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

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

i = A("i")
g = B("g")
a = B("a")
l = B("l")
n = A("n")
k = B("k")
b = A("b")
d = A("d")
e = A("e")
m = A("m")

i.y = l
g.p = l
a.p = g
l.p = a
n.y = k
k.p = a
b.y = l
d.y = l
e.y = l
m.y = l
assert a.p.p.p.p.p.p.txt == "a"