You don't need trig rules, you need ALGEBRA rules. Choose which function you want to solve for (either p or q), which means you need to eliminate the other function.

Say you want to eliminate p, you will need to multiply all the first equation by cos(2x) and all the second equation by sin(2x) so that p has the same coefficients in both equations, then add the equations.