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

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

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

k.y = i
a.x = k
i.x = k
assert i.x.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

k.y = i
a.x = k
i.x = k
assert i.x.y.x.txt == "k"