naive implementation of Q