Vote (Large)

Given N supporters of A and M of B in random arrival order, find the probability A leads after every vote; a ballot-problem computation.

Medium5CombinatoricsProbabilityMathDynamic programmingNo attempts yetTime limit5sMemory limit512 MB

Problem

Candidates A and B are the only two people running in an election. Polling already tells us that exactly NN voters support A and exactly MM voters support B. Since NN is greater than MM, A wins.

Voters arrive at the polling place one at a time. Their order is chosen uniformly at random among all (N+M)!(N + M)! possible orders. After each vote is cast, the poll worker updates the running count and writes down which candidate is ahead so far. If the two counts are equal, no candidate is ahead.

Compute the probability that A stays ahead the whole time, meaning that A is ahead right after every single vote.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers NN and MM, the number of voters supporting A and the number supporting B.

Limits

  • 1T1001 \le T \le 100
  • 0M<N20000 \le M < N \le 2000

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the probability that A is ahead right after every vote.

Print yy with exactly eight digits after the decimal point. If the exact value does not stop at the eighth decimal digit, round it at that digit, and round up when the remainder falls exactly halfway. For example, a probability of 1/512=0.0019531251/512 = 0.001953125 prints as 0.00195313.

Explanation

Take N=2N = 2 and M=1M = 1. There are three voters, two of whom support A. Call those two A1 and A2. The six possible arrival orders are A1 A2 B, A2 A1 B, A1 B A2, A2 B A1, B A1 A2, B A2 A1. Only the first two keep A ahead right after every vote. With the order A1 B A2, A is ahead after the first vote but tied after the second. So the answer is 2/6=0.333333332/6 = 0.33333333.

Take N=1N = 1 and M=0M = 0. There is a single voter and that voter supports A. Only one order is possible, and A is ahead after that one vote.