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

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

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

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

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

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

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

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

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

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

i.p = m
i.s = a
i.w = h
a.v = h
a.s = i
a.y = i
h.y = a
h.z = i
m.x = a
m.z = i
assert a.v.y.v.y.txt == "a"