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

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

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

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

k = A("k")
h = B("h")
b = C("b")
n = D("n")

k.w = n
h.q = n
h.v = b
h.z = b
h.u = b
b.p = n
b.x = k
b.r = k
n.w = k
n.y = h
assert k.w.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

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

k = A("k")
h = B("h")
b = C("b")
n = D("n")

k.w = n
h.q = n
h.v = b
h.z = b
h.u = b
b.p = n
b.x = k
b.r = k
n.w = k
n.y = h
assert k.w.y.u.txt == "b"