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

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

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

m = A("m")
a = B("a")
e = C("e")
k = A("k")
l = C("l")
c = B("c")

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

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

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

m = A("m")
a = B("a")
e = C("e")
k = A("k")
l = C("l")
c = B("c")

m.p = c
a.p = c
a.o = l
e.w = m
e.y = a
k.p = a
l.w = k
l.y = c
c.p = a
c.o = l
assert a.p.o.y.p.p.o.txt == "l"