I think this one should be for both p and q, then range fill, then permute the first m.