#BTCODEA. Traversing Grid
Traversing Grid
Given 2 points in 2 dimensional space (xs, ys) and (xd, yd), your task is to find whether (xd, yd) can be reached from (xs, ys) by making a sequence of zero or more operations.
From a given point (x, y), the operations possible are:
- Move to point (y, x)
- Move to point (x, -y)
- Move to point (x + y, y)
- Move to point (2 * x, y)
Input
The first line of input contains T, the number of test cases. T lines follow, one for each test case. For each test case, the input contains one line denoting the 4 integers xs, ys, xd, yd
Output
Output T lines, one for each test case. For each test case, output "YES" if (xd, yd) is reachable from (xs, ys) and "NO" otherwise. (quotes for clarity)
Example
Input: 1 1 1 2 2</p>Output: YES
Constraints
T ≤ 25
-1010 ≤ xs, ys, xd, yd ≤ 1010
Note that, although the input values are constrained by the above inequality, the coordinates of the points at the intermediate steps need not be.
Explanation
Test case 1: We can move in the following manner: (1,1) → (2,1), using the operation (x, y) → (2 * x, y). Then, move from (2, 1) → (1, 2), using the operation (x, y) → (y, x). Finally use the operation (x, y) → (2 * x, y) to move from (1, 2) → (2, 2).