Here's one way to do it. Suppose the location of B is given by . Then Pythagoras' theorem tells you that and .

Multiply out the brackets in the second of those equations, subtract the first equation, and you'll get a simple linear relation between p and q. Solve this for q, substitute that into the equation , and you'll have a quadratic equation for p. That will have two solutions, and you want the larger one (because B has to lie to the east of A).