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

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

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

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

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

d.x = h
d.w = a
d.q = a
m.w = a
m.r = a
m.v = d
a.p = d
a.u = d
a.v = h
a.s = h
h.w = m
h.r = m
h.u = d
assert d.q.p.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.w: C = None
        self.q: C = None
        self.txt = txt

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

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

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

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

d.x = h
d.w = a
d.q = a
m.w = a
m.r = a
m.v = d
a.p = d
a.u = d
a.v = h
a.s = h
h.w = m
h.r = m
h.u = d
assert d.q.p.x.w.txt == "m"