Problem D. Doubly-periodic world

Author:A. Baranov   Time limit:1 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

The scientists of Flatland have discovered that the universe they live in is topologically similar to the surface of a torus.

This means that along each coordinate axis x and y, the periodicity condition is satisfied with a respective period Lx and Ly.
In other words, points at coordinates (x + u ⋅ Lx, y + v ⋅ Ly) with any integer values u and v are identical.

For the purpose of a scientific experiment, a ray is emitted from a point with coordinates (0, 0), directed by the vector D⃗ = (dx, dy).
It is required to determine the distance the ray will travel before reaching the initial point.

The result should be expressed in units equal to the length of the vector D⃗,
In other words, the task is to find the minimum coefficient λ 0, such that by shifting the vector, one can reach the initial point.

The obtained number should be represented as an irreducible fraction: λ  = αβ.

Input format

The beginning of the input data contains a natural numbe n, followed by exactly n queries,
each specified by a set of integers: Lxi, Lyi, dxi и dyi.

Output format

The output data should contain the values αi и βi,
obtained in response to each i-th query.

Constraints

1 ≤ (Lxi, Lyi) ≤ 106,  − 106 ≤ (dxi, dyi) ≤ 106, |dxi| + |dyi| > 0,
1 ≤ n ≤ 105.

Sample tests

No. Standard input Standard output
1
4

17 18 -6 -8
15 16 6 8
13 14 4 0
10 12 0 2
153 2
10 1
13 4
6 1

0.083s 0.021s 13