P8155 [CF2034A] 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 $a$ and $b$. To unlock the vault, the challenger must determine the smallest key number $m$ that satisfies two conditions:

  • $m$ must be greater than or equal to at least one of $a$ and $b$.
  • The remainder when $m$ is divided by $a$ must be equal to the remainder when $m$ is divided by $b$.

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

Input

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

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

Output

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

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 4 6 472 896
样例输出
12 52864
提示

In the first test case, you can see that:

  • $4 \bmod 4 = 0$ but $4 \bmod 6 = 4$
  • $5 \bmod 4 = 1$ but $5 \bmod 6 = 5$
  • $6 \bmod 4 = 2$ but $6 \bmod 6 = 0$
  • $7 \bmod 4 = 3$ but $7 \bmod 6 = 1$
  • $8 \bmod 4 = 0$ but $8 \bmod 6 = 2$
  • $9 \bmod 4 = 1$ but $9 \bmod 6 = 3$
  • $10 \bmod 4 = 2$ but $10 \bmod 6 = 4$
  • $11 \bmod 4 = 3$ but $11 \bmod 6 = 5$