Guessing Game

No attempts yetTime limit1sMemory limit128 MB

Problem

Hektor loves looking after his younger sister Kornelia, and the two never run out of games to play. Today they are playing a guessing game.

The game needs NN square cells laid out in a row. First, Kornelia paints a run of cells starting from the front: she paints the first xx cells, where xx can be any value from 00 to NN (she may paint none of them, or all of them). When she is done, she covers each cell with a piece of paper so you cannot tell whether it was painted.

Now it is Hektor's turn. He must figure out how many cells Kornelia painted. Hektor may uncover cells of his choice over several rounds; in each round he may uncover (simultaneously) at most KK of the still-covered cells. Each uncovered cell reveals whether or not it was painted.

Compute the minimum number of rounds for which a strategy of choosing which cells to uncover exists that guarantees determining the number of painted cells.

Input

The first line contains the number of test cases ZZ (1Z101 \le Z \le 10). Each of the next ZZ lines contains the two natural numbers NN and KK described above, separated by a space (1N,K1061 \le N, K \le 10^6).

Output

For each test case, print on its own line the minimum number of rounds that guarantees success.

Hint

For N=5N = 5, K=2K = 2, two rounds are enough, for example with the following strategy. In the first round Hektor uncovers cells 2 and 4.

  • If both cells 2 and 4 turn out painted, uncovering cell 5 in the second round tells whether Kornelia painted 4 or 5 cells.
  • If cell 2 is painted but cell 4 is not, uncovering cell 3 in the second round tells whether she painted 2 or 3 cells.
  • If neither cell 2 nor cell 4 is painted, uncovering cell 1 in the second round tells whether she painted 1 cell or none.

One round, on the other hand, is not enough: whatever cells Hektor uncovers in the first round, it can still happen that he cannot pin down the count. For example, if he uncovers cells 2 and 4 and only cell 2 is painted, he cannot tell 2 from 3; and if he uncovers cells 1 and 2 and both are painted, he cannot tell which of 2, 3, 4, or 5 cells were painted.