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

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

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

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

h = A("h")
d = B("d")
a = C("a")
b = D("b")

h.x = d
h.q = b
h.s = a
h.v = a
d.z = b
a.s = h
b.z = d
b.w = h
b.x = a
assert a.s.x.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.q: D = None
        self.s: C = None
        self.v: C = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
a = C("a")
b = D("b")

h.x = d
h.q = b
h.s = a
h.v = a
d.z = b
a.s = h
b.z = d
b.w = h
b.x = a
assert a.s.x.z.w.txt == "h"