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

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

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

n = A("n")
i = B("i")
e = C("e")
m = A("m")
h = A("h")
j = B("j")
d = C("d")

n.z = h
n.r = i
i.s = e
e.p = m
m.z = h
m.r = i
h.z = m
h.r = j
j.s = e
d.p = m
assert e.p.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: B = None
        self.txt = txt

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

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

n = A("n")
i = B("i")
e = C("e")
m = A("m")
h = A("h")
j = B("j")
d = C("d")

n.z = h
n.r = i
i.s = e
e.p = m
m.z = h
m.r = i
h.z = m
h.r = j
j.s = e
d.p = m
assert e.p.z.z.z.z.txt == "m"