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

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

e = A("e")
d = B("d")
l = B("l")
c = A("c")
m = A("m")
a = A("a")

e.y = c
d.y = e
d.p = l
l.y = e
l.p = d
c.y = a
m.y = e
a.y = e
assert e.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

e = A("e")
d = B("d")
l = B("l")
c = A("c")
m = A("m")
a = A("a")

e.y = c
d.y = e
d.p = l
l.y = e
l.p = d
c.y = a
m.y = e
a.y = e
assert e.y.y.y.y.y.txt == "a"