Tennis contest Nadal or Djokovic? Who is the best one?

The two most famous tennis players, A and B, are facing each other in up to 2n − 1 matches. The one who wins n matches will be the best player in the world. We supose the result of each game doesn’t depend on the rest, and there is a constant likelihood, p, of A to win a match. Draw is an invalid result. Which is in advance the probability of A to win the title? Input The first line of the input contains an integer, t, indicating the number of test cases. For each test case, two lines appear, the first one contains a number n, 1 ≤ n ≤ 25, representing the number of wins A has to reach. The second line contains a number p, 0 ≤ p ≤ 1, representing the probability of A to win a match. Output For each test case the output should contain a single line with the number representing the probability in advance of A to win the title of best player in the world. Sample Input 5 25 0.5 25 0.4 25 0.6 15 0.8 10 0.95 Sample Output 0.50 0.08 0.92 1.00 1.00