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

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

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

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

h = A("h")
k = B("k")
j = C("j")
i = D("i")

h.v = i
k.x = i
k.w = i
k.y = i
j.w = k
i.r = h
i.w = j
i.z = k
assert h.v.z.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

h = A("h")
k = B("k")
j = C("j")
i = D("i")

h.v = i
k.x = i
k.w = i
k.y = i
j.w = k
i.r = h
i.w = j
i.z = k
assert h.v.z.x.w.txt == "j"