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

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

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

c = A("c")
d = B("d")
a = C("a")
h = A("h")
i = B("i")
e = C("e")

c.p = d
c.s = a
d.s = e
d.q = e
a.s = e
a.p = i
h.p = d
h.s = a
i.s = e
i.q = a
e.s = a
e.p = d
assert c.p.s.p.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: C = None
        self.txt = txt

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

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

c = A("c")
d = B("d")
a = C("a")
h = A("h")
i = B("i")
e = C("e")

c.p = d
c.s = a
d.s = e
d.q = e
a.s = e
a.p = i
h.p = d
h.s = a
i.s = e
i.q = a
e.s = a
e.p = d
assert c.p.s.p.s.p.s.txt == "e"