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

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

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

a = A("a")
n = B("n")
m = C("m")
l = B("l")
c = C("c")
i = A("i")
j = A("j")
h = C("h")
d = B("d")

a.w = n
n.p = l
n.s = m
m.y = d
m.s = a
l.p = n
l.s = h
c.y = l
c.s = j
i.w = l
j.w = n
h.y = n
h.s = i
d.p = n
d.s = h
assert m.y.p.s.y.p.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

a = A("a")
n = B("n")
m = C("m")
l = B("l")
c = C("c")
i = A("i")
j = A("j")
h = C("h")
d = B("d")

a.w = n
n.p = l
n.s = m
m.y = d
m.s = a
l.p = n
l.s = h
c.y = l
c.s = j
i.w = l
j.w = n
h.y = n
h.s = i
d.p = n
d.s = h
assert m.y.p.s.y.p.s.s.txt == "a"