I assume your picture shows two carts, on a level surface, connected by a rope passing over a pulley at some point above and between them. The height of the pulley is 12 ft. Let x be the distance from Q to one cart and y the distance from Q to the other cart. Then the hypotenuse of the right triangle formed by the first cart, P, and Q, is given by \sqrt{x^2+ 144}. The hypotenuse of the right triangle formed by the second cart, P, and Q, is given by \sqrt{y^2+ 144}. The two hypotenuses form the entire length of the rope: \sqrt{x^2+ 144}+ \sqrt{y^2+ 144}= 39. That's the formula you have. Well, done!
That is the "static" formula. To get a "dynamic" formula, relating the rates of motion, differentiate both sides with respect to t, using the chain rule. Your final formula will involve both dx/dt and dy/dt. You are given one and asked to find the other.