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

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

k = A("k")
h = B("h")
i = B("i")
d = A("d")

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

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

k = A("k")
h = B("h")
i = B("i")
d = A("d")

k.z = d
h.y = k
h.w = i
i.y = k
i.w = h
d.z = k
assert i.y.z.z.txt == "k"