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

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

a = A("a")
k = B("k")
n = B("n")
i = A("i")
h = A("h")

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

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

a = A("a")
k = B("k")
n = B("n")
i = A("i")
h = A("h")

a.w = i
k.z = n
n.z = k
i.w = h
h.w = i
assert n.z.z.z.z.txt == "n"