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

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

c.q = k
k.r = c
l.q = k
assert c.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

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

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