Hide

Problem J
Pull the Queen

Your friend invents a mysterious card game and wants you to bet all your money on it. Suspicious of his motives, you decide to analyze the game before agreeing. He also claims that if you win within a certain number of turns, you receive an even larger reward. The game uses a standard deck of 52 cards, containing 4 cards of each rank.

Objective

The goal is to pull a Queen from the deck. The player who pulls a Queen wins immediately.

Rules

One of you goes first. Call the first player Player A and the second player, Player B. The players alternate drawing cards from the deck until a Queen is drawn.

Each card has the following behavior:

Card

Action

King

Return this card to the deck and reshuffle.

Queen

Game ends immediately. The player who drew it wins.

Other

Remove the card from the deck and continue.

A turn consists of both players drawing once (i.e., one draw by Player A and one draw by Player B).

Input

The first line of input contains a single integer $N$ ($1 \leq N \leq 100$). Each of the next $N$ lines contains a case in the format “$p\ M$”, where:

  • $p \in \{ \texttt{A}, \texttt{B}\} $ indicates which player you are,

  • $1 \leq M \leq 50$ is the maximum number of turns allowed.

Output

For each test case, output the probability that you win the game by drawing a Queen in $M$ or fewer turns.

Your answer must have an absolute error of at most $10^{-10}$.

Sample Input 1 Sample Output 1
2
A 1
A 2
0.0769230769231
0.1447622487552
Sample Input 2 Sample Output 2
3
A 3
B 2
B 12
0.2042905382172
0.1358715967826
0.4414500410073

Please log in to submit a solution to this problem

Log in