Let H be the point where the height drawn from Q falls.
Focus on QHR. It is a right triangle with legs QH and 3 and hypothenuse 5.
We can find QH using the pythagorean theorem:

Now, focus on QHP. It is again a right triangle, and this time we know both legs (QH=4, PH = 6) and we're looking for the hypothenuse:
