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

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

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

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

k = A("k")
i = B("i")
g = C("g")
e = D("e")

k.w = g
i.z = k
i.q = e
g.r = i
g.z = i
e.s = i
assert g.z.q.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

k = A("k")
i = B("i")
g = C("g")
e = D("e")

k.w = g
i.z = k
i.q = e
g.r = i
g.z = i
e.s = i
assert g.z.q.s.z.txt == "k"