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

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

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

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

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

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

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