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

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

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

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

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

k.w = c
k.z = c
k.p = m
k.x = m
d.o = k
d.x = k
m.w = k
m.p = c
c.u = k
c.r = d
assert m.w.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.z: D = None
        self.p: C = None
        self.x: C = None
        self.txt = txt

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

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

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

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

k.w = c
k.z = c
k.p = m
k.x = m
d.o = k
d.x = k
m.w = k
m.p = c
c.u = k
c.r = d
assert m.w.w.r.txt == "d"