CF2075A.To Zero

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

To Zero

You are given two integers nn and kk; kk is an odd number not less than 33. Your task is to turn nn into 00.

To do this, you can perform the following operation any number of times: choose a number xx from 11 to kk and subtract it from nn. However, if the current value of nn is even (divisible by 22), then xx must also be even, and if the current value of nn is odd (not divisible by 22), then xx must be odd.

In different operations, you can choose the same values of xx, but you don't have to. So, there are no limitations on using the same value of xx.

Calculate the minimum number of operations required to turn nn into 00.

Input

The first line contains one integer tt (1t100001 \le t \le 10000) — the number of test cases.

Each test case consists of one line containing two integers nn and kk (3kn1093 \le k \le n \le 10^9, kk is odd).

Output

For each test case, output one integer — the minimum number of operations required to turn nn into 00.

Note

In the first example from the statement, you can first subtract 55 from 3939 to get 3434. Then subtract 66 five times to get 44. Finally, subtract 44 to get 00.

In the second example, you can subtract 33 once, and then subtract 22 three times.

In the third example, you can subtract 22 three times.

Samples

8
39 7
9 3
6 3
999967802 3
5 5
6 5
999999999 3
1000000000 3
7
4
3
499983901
1
2
499999999
500000000

在线编程 IDE

建议全屏模式获得最佳体验