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

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

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

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

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

n.z = b
c.s = e
c.w = e
e.v = c
e.o = c
e.r = n
b.p = m
m.p = b
assert c.s.r.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

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

n.z = b
c.s = e
c.w = e
e.v = c
e.o = c
e.r = n
b.p = m
m.p = b
assert c.s.r.z.p.txt == "m"