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

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

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

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

d.p = k
d.s = i
d.t = c
a.r = b
a.z = d
k.s = b
k.q = i
b.r = a
b.z = d
c.p = i
c.s = k
c.t = d
h.p = i
h.s = k
h.t = c
i.s = a
i.q = k
assert a.z.p.q.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.s: C = None
        self.t: A = None
        self.txt = txt

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

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

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

d.p = k
d.s = i
d.t = c
a.r = b
a.z = d
k.s = b
k.q = i
b.r = a
b.z = d
c.p = i
c.s = k
c.t = d
h.p = i
h.s = k
h.t = c
i.s = a
i.q = k
assert a.z.p.q.s.z.txt == "d"