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

class B:
    def __init__(self, txt: str):
        self.p: D = None
        self.x: C = None
        self.w: E = None
        self.y: A = None
        self.u: D = None
        self.txt = txt

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

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

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

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

n.z = g
n.p = g
g.p = m
g.u = m
g.x = d
g.w = i
g.y = n
d.u = g
d.r = n
d.o = i
m.t = d
m.q = n
i.z = n
i.p = m
i.w = m
i.r = g
assert n.z.x.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.p: D = None
        self.x: C = None
        self.w: E = None
        self.y: A = None
        self.u: D = None
        self.txt = txt

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

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

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

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

n.z = g
n.p = g
g.p = m
g.u = m
g.x = d
g.w = i
g.y = n
d.u = g
d.r = n
d.o = i
m.t = d
m.q = n
i.z = n
i.p = m
i.w = m
i.r = g
assert n.z.x.o.z.txt == "n"