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

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

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

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

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

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

a.x = n
k.w = a
n.x = a
assert k.w.x.x.txt == "a"