Problem: Problem Statement

Texas hold 'em is one of the standard poker games, originated in Texas, United States. It is played with a standard deck of 52 cards, which has 4 suits (spades, hearts, diamonds and clubs) and 13 ranks (A, K, Q, J and 10-2), without jokers.

With betting aside, a game goes as described below.

At the beginning each player is dealt with two cards face down. These cards are called hole cards or pocket cards, and do not have to be revealed until the showdown. Then the dealer deals three cards face up as community cards, i.e. cards shared by all players. These three cards are called the flop. The flop is followed by another community card called the turn then one more community card called the river.

After the river, the game goes on to the showdown. All players reveal their hole cards at this point. Then each player chooses five out of the seven cards, i.e. their two hole cards and the five community cards, to form a hand. The player forming the strongest hand wins the game. There are ten possible kinds of hands, listed from the strongest to the weakest:

* Royal straight flush: A, K, Q, J and 10 of the same suit. This is a special case of straight flush.
* Straight flush: Five cards in sequence (e.g. 7, 6, 5, 4 and 3) and of the same suit.
* Four of a kind: Four cards of the same rank.
* Full house: Three cards of the same rank, plus a pair of another rank.
* Flush: Five cards of the same suit, but not in sequence.
* Straight: Five cards in sequence, but not of the same suit.
* Three of a kind: Just three cards of the same rank.
* Two pairs: Two cards of the same rank, and two other cards of another same rank.
* One pair: Just a pair of cards (two cards) of the same rank.
* High card: Any other hand.



For the purpose of a sequence, J, Q and K are treated as 11, 12 and 13 respectively. A can be seen as a rank either next above K or next below 2, thus both A-K-Q-J-10 and 5-4-3-2-A are possible (but not 3-2-A-K-Q or the likes).

If more than one player has the same kind of hand, ties are broken by comparing the ranks of the cards. The basic idea is to compare first those forming sets (pairs, triples or quads) then the rest cards one by one from the highest-ranked to the lowest-ranked, until ties are broken. More specifically:

* Royal straight flush: (ties are not broken)
* Straight flush: Compare the highest-ranked card.
* Four of a kind: Compare the four cards, then the remaining one.
* Full house: Compare the three cards, then the pair.
* Flush: Compare all cards one by one.
* Straight: Compare the highest-ranked card.
* Three of a kind: Compare the three cards, then the remaining two.
* Two pairs: Compare the higher-ranked pair, then the lower-ranked, then the last one.
* One pair: Compare the pair, then the remaining three.
* High card: Compare all cards one by one.



The order of the ranks is A, K, Q, J, 10, 9, ..., 2, from the highest to the lowest, except for A next to 2 in a straight regarded as lower than 2. Note that there are exceptional cases where ties remain. Also note that the suits are not considered at all in tie-breaking.

Here are a few examples of comparison (note these are only intended for explanatory purpose; some combinations cannot happen in Texas Hold 'em):

* J-J-J-6-3 and K-K-Q-Q-8.




The former beats the latter since three of a kind is stronger than two pairs.

* J-J-J-6-3 and K-Q-8-8-8.




Since both are three of a kind, the triples are considered first, J and 8 in this case. J is higher, hence the former is a stronger hand. The remaining cards, 6-3 and K-Q, are not considered as the tie is already broken.

* Q-J-8-6-3 and Q-J-8-5-3.




Both are high cards, assuming hands not of a single suit (i.e. flush). The three highest-ranked cards Q-J-8 are the same, so the fourth highest are compared. The former is stronger since 6 is higher than 5.

* 9-9-Q-7-2 and 9-9-J-8-5.




Both are one pair, with the pair of the same rank (9). So the remaining cards, Q-7-2 and J-8-5, are compared from the highest to the lowest, and the former wins as Q is higher than J.

Now suppose you are playing a game of Texas Hold 'em with one opponent, and the hole cards and the flop have already been dealt. You are surprisingly telepathic and able to know the cards the opponent has. Your ability is not, however, as strong as you can predict which the turn and the river will be.

Your task is to write a program that calculates the probability of your winning the game, assuming the turn and the river are chosen uniformly randomly from the remaining cards. You and the opponent always have to choose the hand strongest possible. Ties should be included in the calculation, i.e. should be counted as losses.



Input

The input consists of multiple datasets, each of which has the following format:


YourCard_1 YourCard_2
OpponentCard_1 OpponentCard_2
CommunityCard_1 CommunityCard_2 CommunityCard_3


Each dataset consists of three lines. The first and second lines contain the hole cards of yours and the opponent's respectively. The third line contains the flop, i.e. the first three community cards. These cards are separated by spaces.

Each card is represented by two characters. The first one indicates the suit: `S` (spades), `H` (hearts), `D` (diamonds) or `C` (clubs). The second one indicates the rank: `A`, `K`, `Q`, `J`, `T` (10) or `9`-`2`.

The end of the input is indicated by a line with `#`. This should not be processed.

Output

Print the probability in a line. The number may contain an arbitrary number of digits after the decimal point, but should not contain an absolute error greater than 10^{-6}.

Examples

Input

SA SK
DA CA
SQ SJ ST
SA HA
D2 C3
H4 S5 DA
HA D9
H6 C9
H3 H4 H5
#


Output

1.00000000000000000000
0.34444444444444444198
0.63030303030303025391


Input

SA SK
DA CA
SQ SJ ST
SA HA
D2 C3
H4 S5 DA
HA D9
H6 C9
H3 H4 H5


Output

1.00000000000000000000
0.34444444444444444198
0.63030303030303025391

Solution (in CPP):

Solution:
/*
 * 2535.cc: Texas hold 'em
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const string HN[] = {
  "HC", "OP", "TP", "TOK", "S", "F", "FH", "FOK", "SF", "RSF"
};

const char ST[] = {'S', 'H', 'D', 'C'};
const char RK[] = {
  '_', 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'
};

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

enum { H_HC, H_OP, H_TP, H_TOK, H_S, H_F, H_FH, H_FOK, H_SF, H_RSF };

struct Card {
  int s, r;
  Card() {}
  Card(int _s, int _r): s(_s), r(_r) {}
  Card(string cs) {
    switch (cs[0]) {
    case 'S': s = 0; break;
    case 'H': s = 1; break;
    case 'D': s = 2; break;
    case 'C': s = 3; break;
    }
    switch (cs[1]) {
    case 'A': r = 14; break;
    case 'K': r = 13; break;
    case 'Q': r = 12; break;
    case 'J': r = 11; break;
    case 'T': r = 10; break;
    default: r = cs[1] - '0';
    }
  }

  bool operator==(const Card& c) { return r == c.r; }
  bool operator<(const Card& c) { return r < c.r; }
  bool operator>(const Card& c) { return r > c.r; }
  string to_s() { string t; t += ST[s]; t += RK[r]; return t; }
};

/* global variables */

bool used[4][15];

/* subroutines */

int check_hand(Card (&cs)[5], vi &tb) {
  int sns[4] = {}, rns[15] = {};
  int maxsn = 0, maxrn0 = 0, maxrn1 = 0;
  tb.clear();

  for (int i = 0; i < 5; i++) sns[cs[i].s]++, rns[cs[i].r]++;
  for (int i = 0; i < 4; i++)
    if (maxsn < sns[i]) maxsn = sns[i];
  for (int i = 2; i <= 14; i++) {
    if (maxrn0 < rns[i]) maxrn1 = maxrn0, maxrn0 = rns[i];
    else if (maxrn1 < rns[i]) maxrn1 = rns[i];
  }
  //printf("maxsn=%d, maxrn0=%d, maxrn1=%d\n", maxsn, maxrn0, maxrn1);
  
  bool flush = (maxsn == 5);

  bool strt = false;
  if (maxrn0 == 1) {
    int cnt = 0;
    for (int i = 14; i >= 2; i--) {
      if (rns[i]) {
	if (++cnt == 5) {
	  strt = true;
	  tb.push_back(i + 4);
	  break;
	}
      }
      else cnt = 0;
    }
    if (cnt == 4 && rns[14]) {
      strt = true;
      tb.push_back(5);
    }
  }

  if (strt) {
    // Royal straight flush
    if (flush && tb[0] == 14) return H_RSF;
    // Straight flush
    if (flush) return H_SF;
    // Straight
    return H_S;
  }

  vi tbs[5];
  for (int i = 14; i >= 2; i--)
    if (rns[i] > 0) tbs[rns[i]].push_back(i);

  // Four of a kind
  if (maxrn0 == 4) {
    tb.push_back(tbs[4][0]);
    tb.push_back(tbs[1][0]);
    return H_FOK;
  }

  // Full house
  if (maxrn0 == 3 && maxrn1 == 2) {
    tb.push_back(tbs[3][0]);
    tb.push_back(tbs[2][0]);
    return H_FH;
  }

  // Flush
  if (flush) {
    for (int i = 14; i >= 2; i--)
      for (int j = 0; j < rns[i]; j++) tb.push_back(i);
    return H_F;
  }

  // Straight (already done)

  // Three of a kind
  if (maxrn0 == 3) {
    tb.push_back(tbs[3][0]);
    tb.push_back(tbs[1][0]);
    tb.push_back(tbs[1][1]);
    return H_TOK;
  }

  // Two Pair
  if (maxrn0 == 2 && maxrn1 == 2) {
    tb.push_back(tbs[2][0]);
    tb.push_back(tbs[2][1]);
    tb.push_back(tbs[1][0]);
    return H_TP;
  }

  // One Pair
  if (maxrn0 == 2) {
    tb.push_back(tbs[2][0]);
    tb.push_back(tbs[1][0]);
    tb.push_back(tbs[1][1]);
    tb.push_back(tbs[1][2]);
    return H_OP;
  }

  // High card
  tb = tbs[1];
  return H_HC;
}

bool win_hand(int h0, vi &tb0, int h1, vi &tb1) {
  if (h0 != h1) return (h0 > h1);
  for (int i = 0; i < tb0.size(); i++)
    if (tb0[i] != tb1[i]) return (tb0[i] > tb1[i]);
  return false;
}

int rec(Card (&cs)[7], Card (&cs0)[5], vi &tb, int k, int n) {
  //printf("rec(%d,%d)\n", k, n);
  if (k >= 5) {
    //for (int i = 0; i < 5; i++) cout << ' ' << cs0[i].to_s();
    //cout << endl;
    return check_hand(cs0, tb);
  }
  if (n >= 7) return -1;

  int maxh = -1, maxi = min(6, 2 + k);
  vi tb0;

  for (int i = n; i <= maxi; i++) {
    cs0[k] = cs[i];
    int h = rec(cs, cs0, tb0, k + 1, i + 1);
    if (h >= 0 && win_hand(h, tb0, maxh, tb)) {
      maxh = h;
      tb = tb0;
    }
  }

  return maxh;
}

int strongest(Card (&cs)[7], vi &tb) {
  Card cs0[5];
  tb.clear();

  //cout << "strongest:";
  //for (int i = 0; i < 7; i++) cout << ' ' << cs[i].to_s();
  //cout << endl;
  return rec(cs, cs0, tb, 0, 0);
}

/* main */

int main() {
  /*
  //Card c5[5] = {Card("SA"), Card("SK"), Card("SQ"), Card("SJ"), Card("ST")};
  //Card c5[5] = {Card("S9"), Card("SK"), Card("SQ"), Card("SJ"), Card("ST")};
  //Card c5[5] = {Card("HA"), Card("S2"), Card("S3"), Card("S4"), Card("S5")};
  //Card c5[5] = {Card("S9"), Card("H9"), Card("D9"), Card("CK"), Card("SK")};
  Card c5[5] = {Card("S3"), Card("S3"), Card("S3"), Card("SJ"), Card("SQ")};
  //Card c5[5] = {Card("S9"), Card("H9"), Card("D9"), Card("CK"), Card("HA")};
  //Card c5[5] = {Card("S9"), Card("H9"), Card("DQ"), Card("CQ"), Card("HK")};
  //Card c5[5] = {Card("S3"), Card("H3"), Card("D4"), Card("C5"), Card("HA")};
  //Card c5[5] = {Card("S3"), Card("H6"), Card("D4"), Card("C5"), Card("HA")};
  vi tbb;
  int h = check_hand(c5, tbb);
  cout << HN[h];
  for (int i = 0; i < tbb.size(); i++) printf(" %d", tbb[i]); putchar('\n');
  return 0;
  */
  
  string cs00, cs01, cs10, cs11;
  for (;;) {
    cin >> cs00;
    if (cs00 == "#") break;

    memset(used, false, sizeof(used));
    
    cin >> cs01 >> cs10 >> cs11;
    Card h00 = Card(cs00); used[h00.s][h00.r] = true;
    Card h01 = Card(cs01); used[h01.s][h01.r] = true;
    Card h10 = Card(cs10); used[h10.s][h10.r] = true;
    Card h11 = Card(cs11); used[h11.s][h11.r] = true;

    string ccs0, ccs1, ccs2;
    cin >> ccs0 >> ccs1 >> ccs2;
    Card f0 = Card(ccs0); used[f0.s][f0.r] = true;
    Card f1 = Card(ccs1); used[f1.s][f1.r] = true;
    Card f2 = Card(ccs2); used[f2.s][f2.r] = true;

    int win = 0, total = 0;
    Card cs0[7] = {h00, h01, f0, f1, f2};
    Card cs1[7] = {h10, h11, f0, f1, f2};
    
    for (int s0 = 0; s0 < 4; s0++)
      for (int r0 = 2; r0 <= 14; r0++)
	if (! used[s0][r0]) {
	  used[s0][r0] = true;
	  Card tc(s0, r0);
	  cs0[5] = cs1[5] = tc;
	  for (int s1 = 0; s1 < 4; s1++)
	    for (int r1 = 2; r1 <= 14; r1++)
	      if (! used[s1][r1]) {
		used[s1][r1] = true;
		Card rc(s1, r1);
		cs0[6] = cs1[6] = rc;

		vi tb0, tb1;
		int h0 = strongest(cs0, tb0);
		/*
		cout << HN[h0];
		for (int i = 0; i < tb0.size(); i++) printf(" %d", tb0[i]);
		putchar('\n');
		*/
		int h1 = strongest(cs1, tb1);
		/*
		cout << HN[h1];
		for (int i = 0; i < tb1.size(); i++) printf(" %d", tb1[i]);
		putchar('\n');
		*/
		if (win_hand(h0, tb0, h1, tb1)) win++;
		total++;
		
		used[s1][r1] = false;
	      }
	  used[s0][r0] = false;
	}

    //printf("%d/%d\n", win, total);
    printf("%.10lf\n", (double)win / total);
  }  
  return 0;
}