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

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

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

h = A("h")
g = B("g")
l = C("l")
d = B("d")
i = A("i")
j = C("j")
k = C("k")

h.s = i
h.x = d
g.p = d
l.t = g
l.p = h
l.z = d
d.p = g
i.s = h
i.x = d
j.t = d
j.p = h
j.z = g
k.t = g
k.z = g
k.p = h
assert i.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.x: B = None
        self.txt = txt

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

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

h = A("h")
g = B("g")
l = C("l")
d = B("d")
i = A("i")
j = C("j")
k = C("k")

h.s = i
h.x = d
g.p = d
l.t = g
l.p = h
l.z = d
d.p = g
i.s = h
i.x = d
j.t = d
j.p = h
j.z = g
k.t = g
k.z = g
k.p = h
assert i.s.s.s.s.s.txt == "h"