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:
During each turn, the player has only two choices:
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
.