CF2034A.King Keykhosrow's Mystery

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

King Keykhosrow's Mystery

There is a tale about the wise King Keykhosrow who owned a grand treasury filled with treasures from across the Persian Empire. However, to prevent theft and ensure the safety of his wealth, King Keykhosrow's vault was sealed with a magical lock that could only be opened by solving a riddle.

The riddle involves two sacred numbers aa and bb. To unlock the vault, the challenger must determine the smallest key number mm that satisfies two conditions:

  • mm must be greater than or equal to at least one of aa and bb.
  • The remainder when mm is divided by aa must be equal to the remainder when mm is divided by bb.

Only by finding the smallest correct value of mm can one unlock the vault and access the legendary treasures!

Input

The first line of the input contains an integer tt (1t1001 \leq t \leq 100), the number of test cases.

Each test case consists of a single line containing two integers aa and bb (1a,b10001 \leq a, b \leq 1000).

Output

For each test case, print the smallest integer mm that satisfies the conditions above.

Note

In the first test case, you can see that:

  • 4mod4=04 \bmod 4 = 0 but 4mod6=44 \bmod 6 = 4
  • 5mod4=15 \bmod 4 = 1 but 5mod6=55 \bmod 6 = 5
  • 6mod4=26 \bmod 4 = 2 but 6mod6=06 \bmod 6 = 0
  • 7mod4=37 \bmod 4 = 3 but 7mod6=17 \bmod 6 = 1
  • 8mod4=08 \bmod 4 = 0 but 8mod6=28 \bmod 6 = 2
  • 9mod4=19 \bmod 4 = 1 but 9mod6=39 \bmod 6 = 3
  • 10mod4=210 \bmod 4 = 2 but 10mod6=410 \bmod 6 = 4
  • 11mod4=311 \bmod 4 = 3 but 11mod6=511 \bmod 6 = 5

so no integer less than 1212 satisfies the desired properties.

Samples

2
4 6
472 896
12
52864

在线编程 IDE

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