#D6589. Quaternion Multiplication

    ID: 5475 Type: Default 1000ms 134MiB

Quaternion Multiplication

Quaternion Multiplication

An extension of a complex number is called a quaternion. It is a convenient number that can be used to control the arm of a robot because it is convenient for expressing the rotation of an object. Quaternions are usingfourrealnumbers using four real numbers x ,, y ,, z ,, w andspecialnumbers(extendedimaginarynumbers) and special numbers (extended imaginary numbers) i ,, j ,, k .Itisexpressedasx+yi+zj+wk. It is expressed as x + yi + zj + wk . The sum of such quaternions is defined as:

$ (x_1 + y_1 i + z_1 j + w_1 k) + (x_2 + y_2 i + z_2 j + w_2 k) = (x_1 + x_2) + (y_1 + y_2) i + (z_1 + z_2) j + (w_1 + w_2) k $

On the other hand, the product between 1, i i , j j , and k k is given as follows.

This table represents the product AB AB of two special numbers A A and B B . For example, the product ij ij of i i and j j is k k , and the product ji ji of j j and i i is k -k .

The product of common quaternions is calculated to satisfy this relationship. For example, the product of two quaternions, 1+2i+3j+4k 1 + 2i + 3j + 4k and 7+6i+7j+8k 7 + 6i + 7j + 8k , is calculated as follows:

(1+2i+3j+4k) times(7+6i+7j+8k)= (1 + 2i + 3j + 4k) \ times (7 + 6i + 7j + 8k) = 7+6i+7j+8k 7 + 6i + 7j + 8k +14i+12i2+14ij+16ik + 14i + 12i ^ 2 + 14ij + 16ik +21j+18ji+21j2+24jk + 21j + 18ji + 21j ^ 2 + 24jk +28k+24ki+28kj+32k2 + 28k + 24ki + 28kj + 32k ^ 2

By applying the table above

=58+16i+36j+32k = -58 + 16i + 36j + 32k

It will be.

Two quaternions (x1+y1i+z1j+w1k x_1 + y_1 i + z_1 j + w_1 k ) and ()wherethefourcoefficients) where the four coefficients x ,, y ,, z ,, w $ are integers and not all zeros x_2 + y_2 i + z_2 j + w_2 k $), and the product is (x3+y3i+z3j+w3k x_3 + y_3 i + z_3 j + w_3 k ), x3 x_3 , y3 y_3 , z3 z_3 , Createaprogramthatoutputsw3 Create a program that outputs w_3 .

input

Given multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

n n data1 data_1 data2 data_2 :: datan data_n

The first line gives the number of pairs of quaternions to process n n (n leq10 n \ leq 10 ). The following n n line is given the i i th quaternion pair of information datai data_i in the following format:

x1 x_1 y1 y_1 z1 z_1 w1 w_1 x2 x_2 y2 y_2 z2 z_2 w2 w_2

All coefficients given should be -1000 or more and 1000 or less. The number of datasets does not exceed 50.

output

Prints the product of a given set of quaternions for each dataset.

Example

Input

2 1 2 3 4 7 6 7 8 5 6 7 8 3 2 3 4 0

Output

-58 16 36 32 -50 32 28 48

inputFormat

outputFormat

outputs w_3 $.

input

Given multiple datasets. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

n n data1 data_1 data2 data_2 :: datan data_n

The first line gives the number of pairs of quaternions to process n n (n leq10 n \ leq 10 ). The following n n line is given the i i th quaternion pair of information datai data_i in the following format:

x1 x_1 y1 y_1 z1 z_1 w1 w_1 x2 x_2 y2 y_2 z2 z_2 w2 w_2

All coefficients given should be -1000 or more and 1000 or less. The number of datasets does not exceed 50.

output

Prints the product of a given set of quaternions for each dataset.

Example

Input

2 1 2 3 4 7 6 7 8 5 6 7 8 3 2 3 4 0

Output

-58 16 36 32 -50 32 28 48

样例

2
1 2 3 4 7 6 7 8
5 6 7 8 3 2 3 4
0
-58 16 36 32

-50 32 28 48

</p>