class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

k = A("k")
h = B("h")
i = C("i")
e = D("e")
c = D("c")

k.y = h
h.z = e
h.y = k
i.v = h
i.z = h
i.w = h
e.w = i
c.w = i
assert c.w.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

k = A("k")
h = B("h")
i = C("i")
e = D("e")
c = D("c")

k.y = h
h.z = e
h.y = k
i.v = h
i.z = h
i.w = h
e.w = i
c.w = i
assert c.w.z.y.txt == "k"