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

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

k = A("k")
l = B("l")
g = A("g")
i = B("i")

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

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

k = A("k")
l = B("l")
g = A("g")
i = B("i")

k.x = g
l.y = i
g.x = k
i.y = l
assert l.y.y.y.y.txt == "l"