#ABC475G. 约数最多的数 / Has Many Divisors

约数最多的数 / Has Many Divisors

Problem Statement

You are given integers NN and DD, each at least 22.

Among the positive integers at most NN that are not multiples of DD, find one with the maximum number of positive divisors. If there are multiple such positive integers, output any one of them.

You are given TT test cases; solve each of them.

Constraints

  • 1≤T≤101 \leq T \leq 10
  • 2≤D≤N≤10182 \leq D \leq N \leq 10^{18}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • TT
  • case1\text{case}_1
  • case2\text{case}_2
  • ⋮\vdots
  • caseT\text{case}_T

Here, casei\text{case}_i represents the ii-th test case, and is given in the following format:

  • NN DD

Output

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

4
10 2
17 4
2026 919
1000000000000 48
9
15
1680
843291048600

The positive integers at most 1010 that are not multiples of 22 are the five integers 1,3,5,7,91, 3, 5, 7, 9, and the numbers of their positive divisors are 1,2,2,2,31, 2, 2, 2, 3, respectively. Therefore, output 99 for the first test case.

For the second test case, besides 1515 in the sample output, outputting any of 6,10,146, 10, 14 is also accepted.