puzzle contents
Contents
raw puzzle

Original Problem

Consider two points, p=(px,py)p=(p_x, p_y) and q=(qx,qy)q=(q_x, q_y). We consider the inversion or point reflection, r=(rx,ry)r=(r_x, r_y), of point pp across point qq to be a 180180^{\circ} rotation of point pp around qq.

Given nn sets of points pp and qq, find rr for each pair of points and print two space-separated integers denoting the respective values of rxr_x and ryr_y on a new line.

Input Format

The first line contains an integer, nn, denoting the number of sets of points.
Each of the nn subsequent lines contains four space-separated integers describing the respective values of pxp_x, pyp_y, qxq_x, and qyq_y defining points p=(px,py)p=(p_x,p_y) and q=(qx,qy)q=(q_x,q_y).

Constraints

Output Format

For each pair of points pp and qq, print the corresponding respective values of rxr_x and ryr_y as two space-separated integers on a new line.

Sample Input

2
0 0 1 1
1 1 2 2

Sample Output

2 2
3 3

Explanation

The graphs below depict points pp, qq, and rr for the n=2n=2 points given as Sample Input:


  1. Thus, we print rxr_x and ryr_y as 2 2 on a new line.

  2. Thus, we print rxr_x and ryr_y as 3 3 on a new line.

Solution

The rotation matrix around 180180^\circ is:

R(180)=[cos180sin180sin180cos180]=[1001]R(180^{\circ })={\begin{bmatrix}\cos 180^{\circ } &-\sin 180^{\circ } \\\sin 180^{\circ } &\cos 180^{\circ } \\\end{bmatrix}}={\begin{bmatrix}-1&0\\[3pt]0&-1\\\end{bmatrix}}

Now it's quite easy to translate by point qq, rotate with matrix RR and translate back to qq:

r=q+R(180)(pq)=2qpr = q + R(180^{\circ }) \cdot (p - q) = 2q - p

The final implementation then looks like this in Ruby:

gets.to_i.times{
    x = gets.split.map(&:to_i)
    print 2 * x[2] - x[0], ' ', 2 * x[3] - x[1], "\n"
}