P17215 [ICPC 2017 Nanning R] The Champion

Description

Bob is attending a chess competition. Now the competition is in the knockout phase. There are $2^r$ players now, and they will play over $r$ rounds. In each knockout round, the remaining players would be divided into pairs, and the winner of each pair would advance to the next knockout round. Finally only one player would remain and be declared the champion. Bob has already assigned all players in an order while he assigned himself to the $k$-th site. A better player is located at a site with a smaller number indicating a higher order. The probability that a player with higher order wins a player with lower order is $p (0 \le p \le 1)$. Bob notices that arrangement of matches is crucial for the final result. For example, if there are $4$ players and Bob is the second best player (he is the second site), and $p = 0.9$. In the first round, if Bob meets the best player, he will have only $0.1 \times 0.9 = 0.09$ probability to become the champion. However if he does not meet the best player in the first round, he will have $0.9 \times (0.9 \times 0.1 + 0.1 \times 0.9) = 0.162$ probability to become the champion. Now Bob wants to know, what is the winning probability for him in the best arrangement of matches.

Input Format

The first line in the input contains an integer $t (1 \le t \le 63000)$ which is the number of test cases. For each case, there is only one line containing two integers $r$ and $k$ $(1 \le r < 64,1 \le k \le 2^r)$ and a float-point number $p (0 \le p \le 1)$ as described above.

Output Format

For each case, calculate the winning probability for Bob in the best arrangement. Output the probability with the precision of $6$ digits.