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

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

l = A("l")
m = B("m")
i = A("i")

l.r = m
m.x = l
i.r = m
assert m.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

l = A("l")
m = B("m")
i = A("i")

l.r = m
m.x = l
i.r = m
assert m.x.r.x.txt == "l"