Implementing Q-Matrix.