Time to complete the race for P is
t = D1 / S1 = distance remaining for P / speed ratio of P = 360 / 3x = 120 / x
Now in this time Q had covered the distance is
D2 = S2 * t = speed ratio of Q * time when P complete the race = (120 / x ) * 4x = 480
when P complete the race, Q will cover 480m distance
So, distance between P and Q is 500 – 480 = 20m