Since nobody even left a hint, maybe the problem is not clear enough.

So to clarify, here is an example.

For this specific P-matrix, Q can be build using a series of rotations:

The question is about finding a general procedure to determine the/a Q-matrix, valid for any P-matrix (provided the transformation is possible)