#P7698. [2019年杭电多校]fraction

[2019年杭电多校]fraction

fraction

Problem Description

Many problems require printing the probability of something. Moreover, it is common that if the answer is ab\frac{a}{b}, you should output a×b1(modp)a \times b^{-1} \pmod{p} (pp is a prime number). In these problems, you cannot know the exact value of the probability. It's so confusing!!! Now, we want to reverse engineer the exact probability from such calculated output value xx. We do so by guessing the probability is the one with the minimum bb such that a×b1=x(modp)a \times b^{-1} = x \pmod{p}. Now we invite you to solve this problem with us! You are given two positive integers pp and xx, where pp is a prime number. Please find the smallest positive integer bb such that there exist some positive integer aa satisfying a<ba < b and abx(modp)a \equiv bx \pmod{p}.

Input

The first line contains an integer TT indicating there are TT tests. Each test consists of a single line containing two integers: p,xp, x.

  • 1T2×1051 \le T \le 2 \times 10^5
  • 3p10153 \le p \le 10^{15}
  • pp is a prime
  • 1<x<p1 < x < p

Output

For each test, output a line containing a string represents the fraction ab\frac{a}{b} using the format "a/b" (without quotes).

Sample Input

3

11 7

998244353 554580197

998244353 998244352

Sample Output

2/5

8/9

499122176/499122177

Source

2019 Multi-University Training Contest 5