Faineant Komorebi Loves Game
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Faineant Komorebi comes to play games with Setsuna again! To make the game fun, Komorebi decides to ask Setsuna to create a new game that he has never played before.

Thus, Setsuna gives the rule of the game as follow:

  1. Setsuna brings a pile of stones and chooses a magical number , where .
  2. Komorebi brings a pile of stones, where . So now there are two piles of stones, each containing stones and stones.
  3. Setsuna and Komorebi take turns to take the stones, and Setsuna goes first. If someone can't do any operation in this turn, he loses the game.

During each turn, the player has only two choices:

  1. Take stones from one of the piles, where .
  2. Take stones from Setsuna's pile and stone from Komorebi's pile, where .

Even if Komorebi's brain is exhausted, he still thinks there must be something wrong with the game. When Setsuna gives the number of stones in the first pile, how many stones should Komorebi bring in order to be sure to win?

As Komorebi is quite lazy, if there are multiple answers, output the minimum one.

Formally, when and are determined, find the minimum to ensure that Komorebi wins.

输入描述:

Each test contains multiple test cases.

The first line contains , the number of test cases.

Each test case contains two integers .

输出描述:

Output  lines.

Each line contains an integer indicating the minimum .

示例1

输入

复制
13
735 18
767 11
1016 2
244 22
690 18
721 18
66 20
540 14
398 6
87 12
259 2
824 7
414 19

输出

复制
14016
9275
3356
5626
13154
37
3
8145
55
1140
856
6696
8314