#agc057d. [agc057_d]Sum Avoidance

[agc057_d]Sum Avoidance

Problem Statement

You are given positive integers SS and KK. A sequence of positive integers A=(A1,A2,ldots,AN)A = (A_1, A_2, \\ldots, A_N) is said to be a good sequence when satisfying the following two conditions.

  • 1leqA1<A2<cdots<ANleqS11\\leq A_1 < A_2 < \\cdots < A_N \\leq S - 1 holds.
  • sumi=1NAixineqS\\sum_{i=1}^NA_ix_i\\neq S holds for any sequence of non-negative integers (x1,x2,ldots,xN)(x_1, x_2, \\ldots, x_N).

Let A=(A1,A2,ldots,AN)A = (A_1, A_2, \\ldots, A_N) be the lexicographically smallest of the good sequences with the maximum number NN of terms. Print the KK-th term AKA_K of this sequence, or -1 if K>NK > N.

We will give you TT test cases; solve each of them.

Constraints

  • 1leqTleq10001\\leq T\\leq 1000
  • 3leqSleq10183\\leq S\\leq 10^{18}
  • 1leqKleqS11\\leq K \\leq S - 1

Input

Input is given from Standard Input in the following format:

TT textcase1\\text{case}_1 vdots\\vdots textcaseT\\text{case}_T

Each case is in the following format:

SS KK

Output

Print TT lines. The ii-th line should contain the answer for textcasei\\text{case}_i.


Sample Input 1

13
3 1
3 2
7 1
7 2
7 3
7 4
10 1
10 2
10 3
10 4
10 5
2022 507
1000000000000000000 999999999999999999

Sample Output 1

2
-1
2
4
6
-1
3
6
8
9
-1
1351
-1

For the cases S=3,7,10S = 3, 7, 10, the sequence AA will be as follows.

  • For S=3S=3: A=(2)A = (2).
  • For S=7S=7: A=(2,4,6)A = (2,4,6).
  • For S=10S=10: A=(3,6,8,9)A = (3,6,8,9).