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

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

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

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

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

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

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

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

a.y = g
a.p = e
l.y = e
l.s = a
l.v = k
n.p = a
e.p = a
g.y = a
g.p = e
k.y = i
k.s = a
k.v = l
i.p = g
assert i.p.p.p.y.p.txt == "e"