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

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

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

f = A("f")
g = B("g")
l = C("l")
m = B("m")
d = C("d")
e = B("e")
n = C("n")
c = B("c")
a = A("a")
j = A("j")

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

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

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

f = A("f")
g = B("g")
l = C("l")
m = B("m")
d = C("d")
e = B("e")
n = C("n")
c = B("c")
a = A("a")
j = A("j")

f.y = a
f.s = m
g.s = c
l.p = c
m.s = c
d.p = g
e.s = m
n.p = e
c.s = e
a.y = f
a.s = e
j.y = f
j.s = c
assert n.p.s.s.s.s.s.s.s.s.txt == "c"