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

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.x: C = None
        self.txt = txt

d = A("d")
i = B("i")
m = C("m")
c = D("c")
k = D("k")

d.s = k
d.v = m
d.q = c
i.z = c
i.r = m
m.w = d
m.v = k
c.r = m
c.x = m
k.r = m
k.x = m
assert k.x.w.s.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.v: C = None
        self.q: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.x: C = None
        self.txt = txt

d = A("d")
i = B("i")
m = C("m")
c = D("c")
k = D("k")

d.s = k
d.v = m
d.q = c
i.z = c
i.r = m
m.w = d
m.v = k
c.r = m
c.x = m
k.r = m
k.x = m
assert k.x.w.s.x.w.txt == "d"