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

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

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

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

a = A("a")
c = B("c")
d = C("d")
k = D("k")
f = B("f")

a.x = c
a.w = c
c.r = a
c.v = d
d.u = k
d.t = k
d.z = a
d.w = a
k.x = f
f.r = a
f.v = d
assert a.w.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: B = None
        self.txt = txt

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

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

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

a = A("a")
c = B("c")
d = C("d")
k = D("k")
f = B("f")

a.x = c
a.w = c
c.r = a
c.v = d
d.u = k
d.t = k
d.z = a
d.w = a
k.x = f
f.r = a
f.v = d
assert a.w.v.w.txt == "a"