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

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

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

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

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

a = A("a")
g = B("g")
m = C("m")
i = D("i")
n = E("n")

a.p = i
g.z = a
g.o = m
m.y = g
i.t = g
i.p = m
n.z = m
n.s = m
assert a.p.p.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

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

a = A("a")
g = B("g")
m = C("m")
i = D("i")
n = E("n")

a.p = i
g.z = a
g.o = m
m.y = g
i.t = g
i.p = m
n.z = m
n.s = m
assert a.p.p.y.z.txt == "a"