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

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

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

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

d = A("d")
m = B("m")
g = C("g")
j = D("j")

d.s = m
d.x = g
m.w = d
m.s = j
g.r = d
g.w = j
j.z = m
assert m.w.s.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.x: C = None
        self.txt = txt

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

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

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

d = A("d")
m = B("m")
g = C("g")
j = D("j")

d.s = m
d.x = g
m.w = d
m.s = j
g.r = d
g.w = j
j.z = m
assert m.w.s.s.z.txt == "m"