We know that the tangent, in a right angle triangle, is the ratio between the opposite cathetus and the joined cathetus.
In this case, is given the tan x=p/q, so we'll conclude that one cathetus is p and the other one is q.
Also, in a right angle triangle,
sin x = opposite cathetus/hypotenuse=p/hypotenuse
But in a right angle triangle, by applying Pythagorean theorem:
(hypotenuse)^2=(cathetus)^2 + (cathetus)^2
(hypotenuse)^2 = p^2 + q^2
We'll substitute the formula above
sin x =p/hypotenuse = p/(p^2 + q^2)^1/2