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

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

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

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

f = A("f")
a = B("a")
m = C("m")
i = D("i")
k = D("k")

f.w = m
a.v = f
a.r = k
m.q = f
m.z = a
m.s = a
m.u = k
i.y = k
i.w = a
k.y = i
k.w = a
assert m.u.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

f = A("f")
a = B("a")
m = C("m")
i = D("i")
k = D("k")

f.w = m
a.v = f
a.r = k
m.q = f
m.z = a
m.s = a
m.u = k
i.y = k
i.w = a
k.y = i
k.w = a
assert m.u.w.r.txt == "k"