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

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

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

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

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

f.u = k
f.r = m
f.v = m
f.s = m
m.s = a
m.z = f
m.q = f
e.w = a
e.z = m
k.x = a
a.w = e
a.z = m
assert m.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: B = None
        self.v: B = None
        self.s: B = None
        self.txt = txt

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

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

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

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

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