Problem H
On or Off
Patak wants to watch TV, specifically his favorite channel 88, because he is absolutely obsessed with the number $8$. He goes to the living room only to find that his annoying brother, Parsa, has stolen the batteries from the remote. To make matters worse, there is no way to turn on the TV without the controller due to some questionable “security measures” that removed all the physical buttons on the TV.
Frustrated, Patak heads to the attic and finds two boxes of batteries. One is labeled “Healthy Batteries” with $N$ batteries inside, and the other is labeled “Dead Batteries” with $M$ batteries (Patak’s father keeps all the dead batteries because their village has no recycling center, and he only makes the long trip to a town with recycling capabilities once a year). As Patak reaches to grab two healthy batteries, he clumsily knocks both boxes off the shelf. All the batteries spill out, mix together, and now Patak has no way of telling the healthy ones from the dead ones.
He brings the pile of batteries back upstairs to the living room. For the TV controller to function, it needs exactly two healthy batteries to be inserted into the two slots of the TV controller. Patak starts picking pairs of batteries, putting them in, and pushing the power button on the controller, but nothing happens. After several failed attempts, he begins to feel frustrated, realizing that he might be at this all day.
Parsa, watching this scene unfold, is having the time of his life seeing his brother so annoyed. However, a mathematical question suddenly pops into his mind: in the worst-case scenario, how many times does Patak have to push the power button on the controller until the TV finally turns on? Consider that Patak is actually a genius and will test the batteries using an optimal strategy to minimize the number of tries required in the worst case. Since Parsa is too lazy to calculate it himself, he has contacted you to solve the problem for him.
Input
The first line of input contains a single integer $T$ ($1 \leq T \leq 8$), representing the number of test cases.
Each of the following $T$ lines contains two integers, $N$ and $M$ ($2 \leq N \leq 88$ and $0 \leq M \leq 88$), representing the number of healthy batteries and dead batteries, respectively.
Output
For each test case, output a single integer $K$ on its own line, representing the minimum number of tries Patak must perform to guarantee the TV turns on in the worst-case scenario.
| Sample Input 1 | Sample Output 1 |
|---|---|
3 2 0 2 1 2 2 |
1 3 6 |
| Sample Input 2 | Sample Output 2 |
|---|---|
3 3 1 4 2 5 3 |
2 3 4 |
