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

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

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

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

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

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

k.r = l
i.o = k
l.o = k
assert k.r.o.r.txt == "l"