CF1844A.Subtraction Game

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

Subtraction Game

You are given two positive integers, aa and bb (a<ba \lt b).

For some positive integer nn, two players will play a game starting with a pile of nn stones. They take turns removing exactly aa or exactly bb stones from the pile. The player who is unable to make a move loses.

Find a positive integer nn such that the second player to move in this game has a winning strategy. This means that no matter what moves the first player makes, the second player can carefully choose their moves (possibly depending on the first player's moves) to ensure they win.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1001 \le t \le 100). The description of the test cases follows.

The only line of each test case contains two integers, aa and bb (1a<b1001 \le a \lt b \le 100).

Output

For each test case, output any positive integer nn (1n1061 \le n \le 10^6) such that the second player to move wins.

It can be proven that such an nn always exists under the constraints of the problem.

Note

In the first test case, when n=2n = 2, the first player must remove a=1a = 1 stone. Then, the second player can respond by removing a=1a = 1 stone. The first player can no longer make a move, so the second player wins.

In the second test case, when n=6n = 6, the first player has two options:

  • If they remove b=5b = 5 stones, then the second player can respond by removing a=1a = 1 stone. The first player can no longer make a move, so the second player wins.
  • If they remove a=1a = 1 stone, then the second player can respond by removing a=1a = 1 stone. Afterwards, the players can only alternate removing exactly a=1a = 1 stone. The second player will take the last stone and win.

Since the second player has a winning strategy no matter what the first player does, this is an acceptable output.

In the third test case, the first player cannot make any moves when n=3n = 3, so the second player immediately wins.

Samples

3
1 4
1 5
9 26
2
6
3

在线编程 IDE

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