Equilibrium State

Compute the equilibrium positions of spring-connected objects in the plane from fixed points, spring strengths, and connections.

Medium6MathMatrixNo attempts yetTime limit1sMemory limit256 MB

Problem

When the sum of the forces acting on an object P is 0, P does not move. P is then said to be in an equilibrium state.

Forces acting on object P

Figure 1. Forces acting on object P

Consider the situation in Figure 2. Two fixed points F1 and F2 lie on the x axis, and object P is attached to springs S1 and S2. Spring S1 joins F1 and P, and spring S2 joins F2 and P. Let w1w_1 and w2w_2 be the elastic coefficients of S1 and S2, and let x(F1)x(F_1) and x(F2)x(F_2) be the x coordinates of F1 and F2. By Hooke's law the force that S1 applies to P is w1×(x(P)x(F1))w_1 \times (x(P) - x(F_1)), and the force that S2 applies to P is w2×(x(P)x(F2))w_2 \times (x(P) - x(F_2)), where x(P)x(P) is the x coordinate of P.

An example of an equilibrium state

Figure 2. An example of an equilibrium state

For example, in Figure 2 with x(F1)=0x(F_1) = 0, x(F2)=7x(F_2) = 7, w1=3w_1 = 3, w2=4w_2 = 4, and P in an equilibrium state, the position of P is determined as x(P)=4x(P) = 4.

Now consider several objects joined by several springs in the plane, as in Figure 3. There are kk fixed points F1,,FkF_1, \ldots, F_k, nn objects P1,,PnP_1, \ldots, P_n, and mm springs S1,,SmS_1, \ldots, S_m, where spring SiS_i has elastic coefficient wiw_i. Each spring joins a fixed point and an object, or two objects. Hooke's law holds in the plane as well: a spring with coefficient ww joining points A and B applies the vector force w×(AB)w \times (A - B) to A, and the same formula applies to the x component and to the y component separately. If every object is attached to at least two springs, all objects eventually reach an equilibrium state, and the position of every object is then determined.

Write a program that computes the positions of the nn objects in the equilibrium state from the coordinates of the kk fixed points, the elastic coefficients of the mm springs, and the connections among objects and fixed points.

Another example of an equilibrium state in the plane

Figure 3. Another example of an equilibrium state in the plane

You can assume the following.

  1. Every object is attached to at least two springs, and any two points among the objects and the fixed points are joined through one or more springs.
  2. At most one spring joins a given (object, object) pair or a given (object, fixed point) pair.
  3. At least three fixed points do not lie on one straight line.
  4. When all objects are in an equilibrium state, no two springs cross each other and no two objects sit at the same position.
  5. No two fixed points have the same coordinates.

Input

Read from standard input. The first line contains the number of test cases TT.

The first line of each test case contains three integers kk (3k1003 \le k \le 100), mm (3m30003 \le m \le 3000), and nn (1n10001 \le n \le 1000), separated by blanks. Here kk is the number of fixed points, mm is the number of springs, and nn is the number of objects.

The ii-th of the next kk lines contains the integer coordinates xix_i and yiy_i (10000xi,yi10000-10000 \le x_i, y_i \le 10000) of fixed point FiF_i.

The ii-th of the next mm lines contains three integers wiw_i, uiu_i, and viv_i. Here wiw_i (1wi1001 \le w_i \le 100) is the elastic coefficient of spring SiS_i, and uiu_i and viv_i are the indices of the two endpoints that SiS_i joins. A negative uiu_i means fixed point FuiF_{-u_i} (1uik1 \le -u_i \le k), and a positive uiu_i means object PuiP_{u_i} (1uin1 \le u_i \le n). Read viv_i the same way.

Output

Write to standard output. For each test case, first print one line holding Test case number : followed by the number of the test case. Numbering starts at 1. Then print nn lines; the ii-th of them holds the index ii and the coordinates xix_i and yiy_i of object PiP_i, separated by single blanks.

Print each coordinate with two digits after the decimal point, rounding at the third digit. Round away from zero, and when the rounded value is zero print 0.00 with no sign. The exact value of every answer coordinate is at least 10610^{-6} away from a rounding boundary, so the string to print is determined.