Real Phobia


Bert is a programmer with a real fear of floating point arithmetic. Bert has quite successfully used rational numbers to write his programs but he does not like it when the denominator grows large.

Your task is to help Bert by writing a program that decreases the denominator of a rational number, whilst introducing the smallest error possible. For a rational number A/B, where B > 2 and 0 < A < B, your program needs to identify a rational number C/D such that all of the following are true:

  • 0 < C < D < B
  • the error |A/B - C/D| is the minimum over all possible values of C and D
  • D is the smallest such positive integer


The input starts with an integer K (1 ≤ K ≤ 1000) that represents the number of cases on a line by itself. Each of the following K lines describes one of the cases and consists of a fraction formatted as two integers, A and B, separated by "/" such that:
  • B is a 32 bit integer strictly greater than 2, and
  • 0 < A < B


For each case, the output consists of a fraction on a line by itself. The fraction should be formatted as two integers separated by "/".

Example input
Example output
Time and memory limit:

  • 2 seconds
  • 256MB

Problem source: A2OJ