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

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

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

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

m = A("m")
i = B("i")
h = C("h")
d = D("d")

m.y = h
m.r = i
m.z = d
i.z = m
h.u = m
h.x = m
h.p = m
d.w = i
assert d.w.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.r: B = None
        self.z: D = None
        self.txt = txt

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

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

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

m = A("m")
i = B("i")
h = C("h")
d = D("d")

m.y = h
m.r = i
m.z = d
i.z = m
h.u = m
h.x = m
h.p = m
d.w = i
assert d.w.z.r.z.txt == "m"