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

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

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

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

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

m.x = d
m.y = n
m.w = n
n.o = d
n.z = d
n.u = h
h.w = m
d.u = n
d.s = h
d.z = h
assert d.u.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.y: B = None
        self.w: B = None
        self.txt = txt

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

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

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

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

m.x = d
m.y = n
m.w = n
n.o = d
n.z = d
n.u = h
h.w = m
d.u = n
d.s = h
d.z = h
assert d.u.u.w.txt == "m"