Infinite Rational Tree

No attempts yetTime limit1sMemory limit256 MB

Problem

The infinite rational tree is a complete binary tree defined as follows.

  • The root is 1/11/1.
  • The left child of p/qp/q is p/(p+q)p/(p+q).
  • The right child of p/qp/q is (p+q)/q(p+q)/q.

The first three levels hold 1/11/1 at the top, then 1/21/2 and 2/12/1, then 1/31/3, 3/23/2, 2/32/3, 3/13/1.

Traversing the tree in level order, one level at a time from the top and left to right inside a level, lists its numbers as a sequence of rationals F(n)F(n). It begins with F(1)=1/1F(1) = 1/1, F(2)=1/2F(2) = 1/2, F(3)=2/1F(3) = 2/1, F(4)=1/3F(4) = 1/3, F(5)=3/2F(5) = 3/2, F(6)=2/3F(6) = 2/3.

Given a fraction p/qp/q in lowest terms, find the number that comes right after it in this sequence. That is, print F(n+1)F(n+1) when F(n)=p/qF(n) = p/q.

Input

The first line has the number of test cases PP. (1P10001 \le P \le 1000)

Each of the next PP lines has a test case number and one fraction in lowest terms, separated by a space.

The fraction is always written as p/q with no space inside it. pp is the numerator and qq is the denominator.

pp and qq are coprime and satisfy 1p,q21474836471 \le p, q \le 2147483647. Every given fraction appears in the tree.

Output

For each test case, print the test case number and the answer on one line, separated by a space.

Write the answer in the same numerator/denominator form as the input, with no space between the two numbers.

In every test case the numerator and the denominator of the answer stay inside the 32-bit integer range.