#AGC057D. [AGC057D] Sum Avoidance

[AGC057D] Sum Avoidance

Score : 11001100 points

Problem Statement

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

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

Let A=(A1,A2,,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

  • 1T10001\leq T\leq 1000
  • 3S10183\leq S\leq 10^{18}
  • 1KS11\leq K \leq S - 1

Input

Input is given from Standard Input in the following format:

TT

case1\text{case}_1

\vdots

caseT\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 casei\text{case}_i.

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
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).