Poker Hands

Time limit1sMemory limit128 MB

Problem

A poker deck contains 52 cards. Each card has a suit — one of clubs, diamonds, hearts, or spades (written C, D, H, S in the input) — and a value — one of 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A (representing 2, 3, …, 10, jack, queen, king, ace). For scoring, suits are unordered, while values run from lowest (2) to highest (A).

A poker hand is 5 cards. Hands are ranked by the following categories, from lowest to highest:

  • High Card. A hand that fits no higher category is ranked by its highest card; ties break on the next highest card, and so on.
  • Pair. Two of the five cards share a value. Two hands that both hold a pair are ranked by the pair's value; if equal, by the remaining cards in decreasing order.
  • Two Pairs. The hand holds two distinct pairs. Ranked by the higher pair, then the lower pair, then the remaining card.
  • Three of a Kind. Three cards share a value. Ranked by that value.
  • Straight. Five cards with consecutive values. Ranked by the highest card.
  • Flush. Five cards of the same suit. Ranked by High Card rules.
  • Full House. Three cards of one value plus a pair. Ranked by the value of the three cards.
  • Four of a Kind. Four cards share a value. Ranked by that value.
  • Straight Flush. Five cards of the same suit with consecutive values. Ranked by the highest card.

Given several pairs of hands, decide for each pair which hand — if either — ranks higher.

Note: an ace is only the highest value, so A 2 3 4 5 is not a straight.

Input

Several lines. Each line lists 10 cards separated by spaces: the first 5 cards form the hand of the player named Black, and the next 5 form the hand of the player named White. Input continues until end of file.

Output

For each input line, print exactly one of the following:

Black wins.
White wins.
Tie.