Best Rational Approximation

For each decimal x in [0,1) and bound M, print the reduced fraction p/q with q at most M that is closest to x, breaking ties by smallest denominator then smallest numerator.

Medium7Number theoryMathBinary searchImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Many microcontrollers have no floating point unit, but they do have a reasonably fast integer divide unit. On such a chip it pays to approximate a floating point constant with a rational value. For example,

355113=3.1415929203539823008849557522124\frac{355}{113} = 3.1415929203539823008849557522124

is a quite good approximation to

π=3.14159265358979323846\pi = 3.14159265358979323846

A best rational approximation p/qp/q to a real number xx with denominator at most MM is a fraction p/qp/q in lowest terms with qMq \le M such that, for every pair of relatively prime integers aa and bb with bMb \le M,

xpqxab\left| x - \frac{p}{q} \right| \le \left| x - \frac{a}{b} \right|

holds.

If several fractions in lowest terms satisfy that condition, the answer is the one with the smallest denominator qq. If the denominators are also equal, the answer is the one with the smallest numerator pp.

Write a program that computes the best rational approximation to a real number xx with denominator at most MM.

Input

The first line contains a single integer PP (1P1000)(1 \le P \le 1000), the number of data sets. Every data set is processed in the same way and independently of the others.

Each data set is one line. It contains the data set number KK (1K1000)(1 \le K \le 1000), the maximum denominator MM (15M100000)(15 \le M \le 100000), and a floating point value xx (0x<1)(0 \le x < 1), separated by spaces. The value xx is written with a decimal point and has at most 18 digits after it. The leading 00 before the decimal point may be omitted.

Output

Print one line for each data set. Each line holds the data set number KK, a single space, the numerator pp of the best rational approximation, a forward slash /, and the denominator qq. The fraction p/qp/q must be in lowest terms.