Consider the set of irreducible fractions A = {n/d | n≤d and d ≤ 10000 and gcd(n,d) = 1}.

You are given a member of this set and your task is to find the largest fraction in this set less than the given fraction.

**Note** : this is a set and so all the members are unique.

**Input: **

The first line of input contains a single integer **T** denoting the number of test cases.

Then **T** test cases follow. The first and only line of each test case consists of two space separated positive integers denoting** n** and **d** where **n/d** is an element of the set A. The fraction **n/d** will be greater than 1/10000.

**Output:**

Corresponding to each test case, in a new line, print the numerator and the denominator of the required irreducible fraction with a space in between.

**Constraints:**

1 ≤ **T** ≤ 100

1 ≤ **n,d** ≤ 10000

**Example:**

**Input**

3

1 8

2 53

7 64

**Output**

1249 9993

377 9991

1091 9975

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

preparecodinginterview_dot_com | 190 |

__murugan__ | 173 |

manvimahajan20 | 140 |

xiaoyan_yunche | 139 |

ShameekAgarwal | 116 |

preparecodinginterview_dot_com | 190 |

__murugan__ | 173 |

manvimahajan20 | 166 |

SoumyaKaushik | 146 |

arpit_anshuman | 140 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.