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

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

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

k = A("k")
d = B("d")
h = C("h")
e = C("e")
j = C("j")
g = B("g")
m = A("m")
c = C("c")

k.s = c
d.z = e
d.p = k
d.q = m
h.p = k
e.p = m
j.p = m
g.z = c
g.p = m
g.q = m
m.s = j
c.p = m
assert e.p.s.p.s.p.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

k = A("k")
d = B("d")
h = C("h")
e = C("e")
j = C("j")
g = B("g")
m = A("m")
c = C("c")

k.s = c
d.z = e
d.p = k
d.q = m
h.p = k
e.p = m
j.p = m
g.z = c
g.p = m
g.q = m
m.s = j
c.p = m
assert e.p.s.p.s.p.s.p.s.txt == "j"