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

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

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

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

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

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

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

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

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

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

d.u = i
d.s = m
d.w = g
g.u = m
i.r = m
i.w = m
i.s = g
m.x = d
m.p = d
m.w = g
assert d.s.w.u.w.txt == "g"