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

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

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

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

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

g.z = a
g.r = i
g.s = d
f.w = d
a.z = d
a.y = d
d.s = i
d.v = a
d.z = g
i.w = d
m.w = d
assert f.w.v.z.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.r: B = None
        self.s: D = None
        self.txt = txt

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

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

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

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

g.z = a
g.r = i
g.s = d
f.w = d
a.z = d
a.y = d
d.s = i
d.v = a
d.z = g
i.w = d
m.w = d
assert f.w.v.z.s.w.txt == "d"