Sherlock and Parentheses (Large)

Given L opening and R closing parentheses, arrange a string of length L+R that maximizes the number of non-empty balanced substrings; output that maximum.

Medium6StringGreedyMathCombinatoricsInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Sherlock and Watson learned about balanced parenthesis strings in a programming class. A string SS made only of the characters ( and ) is balanced when one of the following holds.

  • SS is the empty string.
  • SS has the form (AA), where AA is a balanced string.
  • SS has the form ABAB, where AA and BB are both balanced strings.

Sherlock solved the exercise at once and bragged about it, so Watson gave him another problem. Build a string SS of length L+RL + R that contains exactly LL opening parentheses ( and exactly RR closing parentheses ), and make the number of non-empty balanced substrings as large as possible. Two substrings count as different when they start at different indexes or end at different indexes, even if their contents are the same. SS itself does not have to be balanced.

Sherlock says that once he knows the maximum, he can build the string himself. Given LL and RR, find the maximum possible number of non-empty balanced substrings.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers LL and RR separated by a space.

Output

For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the maximum you found.

Constraints

  • 1T1001 \le T \le 100
  • 0L1050 \le L \le 10^5
  • 0R1050 \le R \le 10^5
  • 1L+R1051 \le L + R \le 10^5

Notes

For L=1L = 1 and R=0R = 0, the only possible string is (, and it has no non-empty balanced substring.

For L=1L = 1 and R=1R = 1, the string () is optimal, and the whole string is the single balanced substring.

For L=3L = 3 and R=2R = 2, both ()()( and (()() reach the maximum of 3. In ()()(, for example, the balanced substrings are () from index 1 to 2, () from index 3 to 4, and ()() from index 1 to 4.