Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

1 March 2023

By Rajan_sust · Limits 1s, 512 MB

Don’t waste your time on the title. You will be given two vectors $ \vec{v_{1}} = x_{1} \hat{i} + y_{1} \hat{j} $ and $ \vec{v_{2}} = x_{2} \hat{i} + y_{2} \hat{j} $. Let $\vec{v_{1}}$ and $\vec{v_{2}}$ form angles $\theta_{1}$ and $\theta_{2}$ with the positive $x$ - axis respectively. Note that the magnitude of $x_{i} \hat{i} + y_{i} \hat{j}$ is defined by $\sqrt{x_{i}^2 + y_{i}^2}$.

We expect a third vector $\vec{v} = x \hat{i} + y \hat{j}$ from you. And you have to make sure 2 properties of $\vec{v}$ .

  1. The magnitude of $\vec{v}$ should be equal to the product of magnitudes of $\vec{v_{1}}$ and $\vec{v_{2}}$.
  2. Angle formed with the positive $x$ - axis of $\vec{v}$ should be equal to the sum of $\theta_{1}$ and $\theta_{2}$.

Input

The first line will contain an integer $T$ ( $1\leqslant T \leqslant 10^5$ ) denoting the number of test cases. For each test case there will be exactly one line that contains four integers $x_{1}, y_{1}, x_{2}, y_{2}$. The values of $x_{1}, y_{1}, x_{2}, y_{2}$ will be in the range $\left[-10^8, +10^8\right]$.

Output

Print $x$ and $y$ in a line for each test case. It is guaranteed that $x$ and $y$ will be integers.

Please refer to the sample input/output section for better understanding.

Sample

InputOutput
2
2 0 0 5
1 1 -1 -1
0 10
0 -2

    Discussion

    Statistics


    39% Solution Ratio

    NirjhorEarliest, 1M ago

    royantar0311Fastest, 0.1s

    shariful_islamLightest, 3.5 MB

    steinumShortest, 187B

    Submit

    Login to submit