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

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

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

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

n = A("n")
k = B("k")
e = C("e")
c = D("c")
m = A("m")
a = C("a")

n.p = m
k.u = a
k.z = c
k.r = c
k.w = n
e.v = c
e.y = c
e.w = m
e.p = k
c.u = e
c.q = k
m.p = n
a.v = c
a.y = c
a.w = m
a.p = k
assert c.u.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

n = A("n")
k = B("k")
e = C("e")
c = D("c")
m = A("m")
a = C("a")

n.p = m
k.u = a
k.z = c
k.r = c
k.w = n
e.v = c
e.y = c
e.w = m
e.p = k
c.u = e
c.q = k
m.p = n
a.v = c
a.y = c
a.w = m
a.p = k
assert c.u.p.w.p.txt == "m"