Bridge Bidding

No attempts yetTime limit1sMemory limit128 MB

Problem

Bridge is a complex card game, and bidding is one of the hardest parts to master. It is made harder because players use different bidding conventions (agreed meanings for bids). In this problem you write a program that suggests the opening bid a player should make. The conventions below are a simplified set.

A bridge hand has 13 cards. Each card has a suit (spades, hearts, diamonds, or clubs) and a rank (A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2), where T stands for the rank 10. Before bidding, a player evaluates the number of high card points (hcp) in the hand and the distribution (how many cards are in each suit). Each card contributes hcp based only on its rank:

Rankhcp
A4
K3
Q2
J1
others0

For example, consider this hand:

  • Spades: A, 2
  • Hearts: K, J, T, 9, 2
  • Diamonds: 3
  • Clubs: K, Q, 7, 4, 3

It has 13 hcp and a distribution of 5-5-2-1 (a distribution is written in non-increasing order). A balanced distribution is any of 4-3-3-3, 4-4-3-2, and 5-3-3-2.

An opening bid is either "Pass" or a level (1-7) together with a trump suit. From highest to lowest, the trump suits rank: No Trump, Spades, Hearts, Diamonds, Clubs. After evaluating the hand, apply the rules below to choose the opening bid. When several rules apply, use the first one that applies. An "x" in a distribution may stand for any non-negative number, and different x's need not be equal.

  1. With at least 10 hcp and a y-x-x-x distribution (y ≥ 8), bid the y-card suit at the 4 level (a preemptive bid).
  2. With 10-13 hcp and a 7-x-x-x distribution, bid the 7-card suit at the 3 level (a preemptive bid).
  3. With 8-9 hcp and a y-x-x-x distribution (y ≥ 7), bid the y-card suit at the 2 level if that suit is Spades or Hearts (a "weak-two" bid).
  4. With 8-11 hcp and a 6-x-x-x distribution in which Spades or Hearts is one of the 6-card suits, bid the higher-ranking suit at the 2 level (a "weak-two" bid).
  5. With 11-15 hcp, a distribution of 4-4-4-1 or 5-4-4-0, and at least 4 spades, bid Diamonds at the 2 level (the "Mini Roman Convention").
  6. With 15-17 hcp and a balanced distribution, bid No Trump at the 1 level, provided at least 3 suits are "stopped". A suit is stopped if it contains at least one of the following: an A; a K and one other card; a Q and two other cards; or a J and three other cards.
  7. With 20-22 hcp and a balanced distribution, bid No Trump at the 2 level.
  8. With at least 22 hcp, bid Clubs at the 2 level.
  9. With 13-16 hcp: a. If there is a suit of 5 or more cards in Spades or Hearts, bid it at the 1 level. If both qualify, bid the longer suit; if they are the same length, bid the higher-ranking suit. b. Otherwise, bid the longer of Diamonds and Clubs at the 1 level (whichever has more cards); if they tie, bid the higher-ranking suit.
  10. With at least 17 hcp, bid the longest suit at the 1 level. If there is a tie, bid the lowest-ranking suit (a "reverse").
  11. If none of the above applies, bid Pass.

In the example hand above, rule 9a applies, so the bid is 1 Hearts.

Input

The input contains several cases. Each case is one line describing a bridge hand, with the 13 cards separated by single spaces. Each card is a two-character string: the first character is the suit (S, H, D, C) and the second is the rank (A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2). The input ends at end-of-file.

Output

For each hand, print one line in the form Hand #k: bid, where k is the hand number starting at 1. The bid is either Pass, or a level followed by a single space and a suit name (No Trump, Spades, Hearts, Diamonds, or Clubs).