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

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

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

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

k = A("k")
i = B("i")
n = C("n")
m = D("m")

k.v = m
k.x = m
i.p = k
i.t = k
i.w = n
n.u = k
m.u = n
m.w = k
assert k.x.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.x: D = None
        self.txt = txt

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

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

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

k = A("k")
i = B("i")
n = C("n")
m = D("m")

k.v = m
k.x = m
i.p = k
i.t = k
i.w = n
n.u = k
m.u = n
m.w = k
assert k.x.w.x.txt == "m"