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

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

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

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

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

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

k.x = i
k.z = i
n.w = i
i.x = k
i.z = k
assert k.z.z.x.txt == "i"