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

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

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

k.z = n
b.s = n
n.z = k
assert k.z.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.s: A = None
        self.txt = txt

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

k.z = n
b.s = n
n.z = k
assert k.z.z.z.txt == "n"