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

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

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

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

m.s = j
l.w = e
l.p = k
g.s = e
c.s = j
j.s = e
a.s = e
k.w = j
k.p = l
e.s = j
assert a.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

m.s = j
l.w = e
l.p = k
g.s = e
c.s = j
j.s = e
a.s = e
k.w = j
k.p = l
e.s = j
assert a.s.s.s.s.txt == "j"