A Rational Sequence 3

Find the rational number at position N in the breadth-first level-order traversal of the Calkin-Wilf-style binary tree rooted at 1/1, where left and right children are p/(p+q) and (p+q)/q.

Medium5TreeMathNumber theoryBinary searchInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

An infinite complete binary tree is labeled with positive rational numbers by the following rules.

  • The label of the root is 1/11/1.
  • The left child of a node labeled p/qp/q is labeled p/(p+q)p/(p+q).
  • The right child of a node labeled p/qp/q is labeled (p+q)/q(p+q)/q.

The top of the tree looks like the figure below.

The top of the binary tree of rational labels

Reading the tree in level order, that is breadth first and left to right within each level, gives the rational sequence FF.

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/3,F(6) = 2/3, \dots

Given an index NN, write a program that computes F(N)F(N).

Input

The first line contains the number of data sets PP (1P10001 \le P \le 1000).

Each of the next PP lines holds one data set. A line contains the data set number KK and the index NN of the element to compute (1N21474836471 \le N \le 2147483647). The data sets are numbered 11 through PP in the order they are given.

The data sets are independent and every one is processed the same way.

Output

Print one line for each data set. On that line print the data set number KK, a single space, the numerator of F(N)F(N), the slash character /, and the denominator of F(N)F(N), in that order with nothing between them. Do not put a space on either side of the slash.

The input is chosen so that neither the numerator nor the denominator exceeds a 32-bit unsigned integer.