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

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

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

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

k = A("k")
e = B("e")
i = C("i")
d = D("d")
a = D("a")

k.q = a
e.v = i
e.x = i
e.w = a
i.v = a
i.w = k
d.r = e
a.r = e
assert k.q.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

k = A("k")
e = B("e")
i = C("i")
d = D("d")
a = D("a")

k.q = a
e.v = i
e.x = i
e.w = a
i.v = a
i.w = k
d.r = e
a.r = e
assert k.q.r.w.txt == "a"