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

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

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

n = A("n")
m = B("m")
h = C("h")
i = C("i")
g = A("g")
b = B("b")
f = B("f")
c = C("c")
k = A("k")

n.z = k
m.r = g
m.p = i
h.q = i
h.p = g
i.q = h
i.p = n
g.z = n
b.r = n
b.p = c
f.r = n
f.p = c
c.q = h
c.p = g
k.z = n
assert i.p.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
h = C("h")
i = C("i")
g = A("g")
b = B("b")
f = B("f")
c = C("c")
k = A("k")

n.z = k
m.r = g
m.p = i
h.q = i
h.p = g
i.q = h
i.p = n
g.z = n
b.r = n
b.p = c
f.r = n
f.p = c
c.q = h
c.p = g
k.z = n
assert i.p.z.z.z.z.z.txt == "k"