CF2009C.The Legend of Freya the Frog

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

The Legend of Freya the Frog

Freya the Frog is traveling on the 2D coordinate plane. She is currently at point (0,0)(0,0) and wants to go to point (x,y)(x,y). In one move, she chooses an integer dd such that 0dk0 \leq d \leq k and jumps dd spots forward in the direction she is facing.

Initially, she is facing the positive xx direction. After every move, she will alternate between facing the positive xx direction and the positive yy direction (i.e., she will face the positive yy direction on her second move, the positive xx direction on her third move, and so on).

What is the minimum amount of moves she must perform to land on point (x,y)(x,y)?

Input

The first line contains an integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

Each test case contains three integers xx, yy, and kk (0x,y109,1k1090 \leq x, y \leq 10^9, 1 \leq k \leq 10^9).

Output

For each test case, output the number of jumps Freya needs to make on a new line.

Note

In the first sample, one optimal set of moves is if Freya jumps in the following way: (0,00,0) \rightarrow (2,02,0) \rightarrow (2,22,2) \rightarrow (3,23,2) \rightarrow (3,53,5) \rightarrow (6,56,5) \rightarrow (6,86,8) \rightarrow (9,89,8) \rightarrow (9,119,11). This takes 8 jumps.

Samples

3
9 11 3
0 10 8
1000000 100000 10
8
4
199999

在线编程 IDE

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