CF2147A.Shortest Increasing Path

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

Shortest Increasing Path

You are at (0,0)(0, 0) in a rectangular grid and want to go to (x,y)(x, y).

In order to do so, you are allowed to perform a sequence of steps.

Each step consists of moving a positive integer amount of length in the positive direction of either the xx or the yy axis.

The first step must be along the xx axis, the second along the yy axis, the third along the xx axis, and so on. Formally, if we number steps from one in the order they are done, then odd-numbered steps must be along the xx axis and even-numbered steps must be along the yy axis.

Additionally, each step must have a length strictly greater than the length of the previous one.

Output the minimum number of steps needed to reach (x,y)(x, y), or 1-1 if it is impossible.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first and only line of each case contains two integers xx and yy (1x,y1091 \le x, y \le 10^9).

Output

For each test case, output the minimum number of steps to reach (x,y)(x, y) or 1-1 if it is impossible.

Note

Visualizer link

In the second test case, you can move to (5,0)(5, 0) by moving 55 along the xx axis and then to (5,6)(5, 6) by moving 66 along the yy axis.

In the third test case, you can move to (1,0)(1, 0), then to (1,2)(1, 2), and finally to (4,2)(4, 2). In the fourth test case, reaching (1,1)(1, 1) is impossible since after moving to (1,0)(1, 0) along the xx axis, you are forced to move at least 22 along the yy axis.

Samples

10
1 2
5 6
4 2
1 1
2 1
3 3
5 1
5 4
752 18572
95152 2322
2
2
3
-1
-1
-1
-1
-1
2
3

在线编程 IDE

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