Under construction

Still being built. Things may change

Fractional XOR Maximization

Time limit2sMemory limit512 MB

Summary
Given rational intervals [a, b] and [c, d], find the supremum of the XOR of binary expansions of one number from each interval.
Level

Hard8 of 10

Topics
Bit manipulation, Greedy, Math
Solved
No attempts yet

Problem

Define the bitwise XOR operation ⊕\oplus for any two real numbers xx and yy as follows. x⊕y=lim⁡n→∞⌊2nx⌋⊕⌊2ny⌋2nx \oplus y = \lim_{n \to \infty}{\frac{\lfloor2^nx\rfloor \oplus \lfloor 2^ny\rfloor}{2^n}} The ⊕\oplus on the right side is the integer bitwise XOR. For example, 58⊕38=34\frac{5}{8} \oplus \frac{3}{8} = \frac{3}{4}, 13⊕17=49\frac{1}{3} \oplus \frac{1}{7} = \frac{4}{9}, and 15⊕17=665\frac{1}{5} \oplus \frac{1}{7} = \frac{6}{65}.

The supremum of a set X⊆RX \subseteq \mathbb{R}, written sup⁡X\sup X, is the least real number that is greater than or equal to every element of XX.

You are given four non-negative rational numbers aa, bb, cc, and dd. Find sup⁡{x⊕y:x∈[a,b],y∈[c,d]}\sup\{x \oplus y : x \in [a, b], y \in [c, d]\}. In other words, find the least value that is greater than or equal to every XOR value formed by an element of [a,b][a, b] and an element of [c,d][c, d].

Input

The first line contains TT (1≤T≤1001 \le T \le 100), the number of test cases. Each test case has two lines. The first line contains four integers anuma_{num}, adenoma_{denom}, bnumb_{num}, bdenomb_{denom} (0≤anum,bnum≤10170 \le a_{num}, b_{num} \le 10^{17}, 1≤adenom,bdenom≤301 \le a_{denom}, b_{denom} \le 30), which describe a=anumadenoma = \frac{a_{num}}{a_{denom}} and b=bnumbdenomb = \frac{b_{num}}{b_{denom}}. The second line describes cc and dd in the same format. Every fraction is irreducible, and a≤ba \le b and c≤dc \le d hold.

Output

Print TT lines. The ii-th line contains the numerator and denominator of x=xnumxdenomx = \frac{x_{num}}{x_{denom}} for the ii-th test case, separated by a single space, as an irreducible fraction.

Hint

In the first test case, the answer is 22. Choosing 11 from the first interval and 1−2p1 - 2^p from the second makes the XOR value arbitrarily close to 22 for a large enough integer pp, but no value equal to or greater than 22 is reachable.

Examples1

  1. Example 1

    Input
    2
    0 1 1 1
    0 1 1 1
    5 7 5 7
    3 16 3 16
    
    Expected output
    2 1
    59 112