You will be given two positive integers A and N and you have to find the smallest positive integer x such that N divides Ax - 1.
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 A and N.
Corresponding to each test case, in a new line, print the smallest positive number x such that N divides Ax - 1. If it is not possible to find such a number x, then print -1.
1 ≤ T ≤ 100
1 ≤ N,A ≤ 10000
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.