Given a positive integer $$$a$$$, we call a function $$$f: \mathbb {Z}^+\to\mathbb {Z}^+$$$ is good if and only if it satisfies:
Consider the smallest good function $$$g$$$ in lexicographical order, please calculate $$$g(x)$$$ for a given $$$x$$$.
Formally, the unique function $$$g$$$ with given $$$a$$$ satisfies:
The input contains several test cases, and the first line contains a positive integer $$$T$$$($$$1 \le T \le 10^5$$$) indicating the number of test cases.
For each test case, there is only one line containing two integers $$$a,x$$$ ($$$ 3 \le a \le 10^9,1 \le x \le 10^9$$$).
For each test case, output one line with one integer $$$g(x)$$$.
53 13 23 34 511 4514
2 3 6 12 16493
| Название |
|---|


