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

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

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

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

m = A("m")
k = B("k")
f = C("f")
l = D("l")
h = A("h")

m.w = l
k.p = l
k.x = h
f.z = l
f.s = k
l.v = f
h.w = l
assert m.w.v.s.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
f = C("f")
l = D("l")
h = A("h")

m.w = l
k.p = l
k.x = h
f.z = l
f.s = k
l.v = f
h.w = l
assert m.w.v.s.x.w.txt == "l"