CF1660A.Vasya and Coins

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

Vasya and Coins

Vasya decided to go to the grocery store. He found in his wallet aa coins of 11 burle and bb coins of 22 burles. He does not yet know the total cost of all goods, so help him find out ss (s>0s \gt 0): the minimum positive integer amount of money he cannot pay without change or pay at all using only his coins.

For example, if a=1a=1 and b=1b=1 (he has one 11-burle coin and one 22-burle coin), then:

  • he can pay 11 burle without change, paying with one 11-burle coin,
  • he can pay 22 burle without change, paying with one 22-burle coin,
  • he can pay 33 burle without change by paying with one 11-burle coin and one 22-burle coin,
  • he cannot pay 44 burle without change (moreover, he cannot pay this amount at all).

So for a=1a=1 and b=1b=1 the answer is s=4s=4.

Input

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

The description of each test case consists of one line containing two integers aia_i and bib_i (0ai,bi1080 \le a_i, b_i \le 10^8) — the number of 11-burle coins and 22-burles coins Vasya has respectively.

Output

For each test case, on a separate line print one integer ss (s>0s \gt 0): the minimum positive integer amount of money that Vasya cannot pay without change or pay at all.

Note

  • The first test case of the example is clarified into the main part of the statement.
  • In the second test case, Vasya has only 11 burle coins, and he can collect either any amount from 11 to 44, but 55 can't.
  • In the second test case, Vasya has only 22 burle coins, and he cannot pay 11 burle without change.
  • In the fourth test case you don't have any coins, and he can't even pay 11 burle.

Samples

5
1 1
4 0
0 2
0 0
2314 2374
4
5
1
1
7063

在线编程 IDE

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