GG NO RE OMG CHEATZ

No attempts yetTime limit3sMemory limit256 MB

Problem

You do not need to know the board game Risk to solve this problem. Every die in this problem is a six sided die.

Rizk is a Bulgarian variant of Risk. Two players fight, each commanding an army. On your turn you either attack or add units to your army, never both. An attack works like this.

Player A attacks with UaU_a units and player B defends with UbU_b units. The attacker has DaD_a dice available and the defender has DdD_d dice available. One attack repeats the following steps.

  1. Player A rolls min(Da,Ua)\min(D_a, U_a) dice.
  2. Player B rolls min(Dd,Ub)\min(D_d, U_b) dice. This differs from ordinary Risk.
  3. Both players sort their dice from highest to lowest and compare them pair by pair. For example, if player A rolled 2, 5, 1, 3 and player B rolled 4, 1, 3, then 5 meets 4, then 3 meets 3, then 2 meets 1. The leftover low rolls of the player who threw more dice take part in no comparison.
  4. In each comparison the losing player loses one unit. The defender wins ties. In the example above, A loses 1 unit and B loses 2 units.
  5. If both players still have at least 1 unit, go back to step 1.

The player who still has units at the end wins the battle. Exactly one player always has units left.

Mike and his brother have been playing for hours. Neither dares to attack, because both fear losing. It is Mike's turn, and he has decided to cheat a little in order to win. He attacks only if his chance of winning this turn is at least 75 percent. Mike has XX units and his brother has YY units. How many units does Mike have to sneak into the game so that his chance of winning this turn is at least 75 percent?

Input

The first line contains one integer TT, the number of test cases. Each of the next TT lines contains four integers DaD_a, DdD_d, XX, YY separated by spaces, with the meaning given above.

  • 1T301 \le T \le 30
  • 1Da,Dd41 \le D_a, D_d \le 4
  • 1X,Y5001 \le X, Y \le 500
  • No test case has a winning probability closer to 0.750.75 than 10610^{-6} when a unit is added to or removed from Mike's army.

Output

For each test case, print on its own line the smallest number of extra units Mike needs so that his chance of winning this turn is at least 75 percent. Print 0 if he already has at least a 75 percent chance.