Blackjack

No attempts yetTime limit1sMemory limit128 MB

Problem

In the game of Blackjack, the player and the dealer are each dealt two cards to start. One of the dealer's cards is placed face up and is visible to the player, while the other is placed face down and is hidden. Given your two cards and the dealer's face-up card, compute the probability that your two-card hand is better than the dealer's two-card hand.

This is not simple: because cards are dealt from the decks without replacement, the probability changes as play proceeds. To keep things simple, we compute the probability only for the moment the cards are first dealt — that is, we assume no cards have been dealt from the decks beforehand.

Card values are as follows.

  • An Ace (A) is worth 1 or 11, chosen by the person holding it.
  • The face cards (K, Q, J) and the ten (T) are each worth 10.
  • Every other card is worth its printed number.

The value of an Ace is chosen so that the hand total is as large as possible without exceeding 21. For a two-card hand it is impossible for the total to exceed 21.

The player beats the dealer when both of the following hold.

  • The player's hand total does not exceed 21; and
  • the player's hand total is greater than the dealer's, or the dealer's hand total exceeds 21.

Several decks may be used together. Each deck has 52 cards, with four each of A, K, Q, J, T, 9, …, 2.

Input

The input consists of several test cases. The first line of each test case contains a positive integer $n$ ($n \le 10$), the number of decks used. The next line contains three characters, separated by spaces, from the set ${A, K, Q, J, T, 9, \dots, 2}$: the dealer's face-up card followed by your two cards, in that order. In each case, assume the $n$ decks have been shuffled together at random. The end of the input is marked by $n = 0$.

Output

For each hand, print on a single line the probability of winning as a percentage, rounded to three decimal places and followed by a percent sign (%).