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

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

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

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

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

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

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

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

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