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

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

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

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

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

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

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