John and Brus believe that number is a very bad number.Thus they try to avoid it every time and everywhere.
Now the guys would like to represent number as a sum of positive numbers,each of which not exceeding .But don’t forget about the bad number !Each summand must not be divisible by ,moreover the number of summands also must not be divisible by .
Your task is to find the minimal possible number of summands in such representation of .
For example,if then we can represent as ,but as far as is divisible by we must have at least summands.But as far as we can’t have summands and thus the answer is .One of the possible ways to represent is .
The first line contains single integer – the number of test cases.Each test case consists of a single line containing three integers and separated by single spaces.
输出格式
For each test case print a single line containing the minimal possible number of summands according to the requirements described above.If it is impossible to do this output -1 (quotes for clarity) instead.