#D6589. Quaternion Multiplication
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 x y z w i j k . 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, , , and is given as follows.
This table represents the product of two special numbers and . For example, the product of and is , and the product of and is .
The product of common quaternions is calculated to satisfy this relationship. For example, the product of two quaternions, and , is calculated as follows:
By applying the table above
It will be.
Two quaternions () and ( 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 (), , , , .
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:
::
The first line gives the number of pairs of quaternions to process (). The following line is given the th quaternion pair of information in the following format:
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:
::
The first line gives the number of pairs of quaternions to process (). The following line is given the th quaternion pair of information in the following format:
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>