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

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

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

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

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

i = A("i")
e = B("e")
g = C("g")
k = D("k")
m = E("m")

i.o = m
i.z = g
i.x = k
e.y = k
e.v = g
e.x = m
g.p = i
g.s = e
k.w = g
m.u = k
m.s = g
assert m.u.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: E = None
        self.z: C = None
        self.x: D = None
        self.txt = txt

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

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

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

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

i = A("i")
e = B("e")
g = C("g")
k = D("k")
m = E("m")

i.o = m
i.z = g
i.x = k
e.y = k
e.v = g
e.x = m
g.p = i
g.s = e
k.w = g
m.u = k
m.s = g
assert m.u.w.p.txt == "i"