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:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

enum yaku
{
	hc, op, tp, tc, st, fl, fh, fc, sf, rsf
};
typedef pii card;
typedef pair<yaku, vi> hand;

card parse(string s)
{
	int suit;
	if (s[0] == 'S') suit = 0;
	else if (s[0] == 'H') suit = 1;
	else  if (s[0] == 'D') suit = 2;
	else if (s[0] == 'C') suit = 3;
	int n;
	if (isdigit(s[1])) n = s[1] - '0';
	else if (s[1] == 'A') n = 1;
	else if (s[1] == 'T') n = 10;
	else if (s[1] == 'J') n = 11;
	else if (s[1] == 'Q') n = 12;
	else if (s[1] == 'K') n = 13;
	return card(n, suit);
}

vector<vi> pat;

void init()
{
	vi v = { 0,1,2,3,4,5,6 };
	do
	{
		vi tmp;
		REP(i, 5) tmp.push_back(v[i]);
		sort(ALL(tmp));
		pat.push_back(tmp);
	} while (next_permutation(ALL(v)));
	sort(ALL(pat));
	pat.erase(unique(ALL(pat)), pat.end());
}

int is_straight(const vector<card>& cards)
{
	vi v;
	for (auto i : cards) v.push_back(i.first);
	if (v == vi{1, 10, 11, 12, 13}) return 14;
	REP(i, 4)
	{
		if (v[i + 1] - v[i] != 1) return 0;
	}
	return v.back();
}

hand calc(const vector<card>& cards)
{
	int straight = is_straight(cards);
	bool flush = true;
	vi rank(13);
	REP(i, 5)
	{
		rank[cards[i].first - 1]++;
		if (i != 4 && cards[i + 1].second != cards[i].second) flush = false;
	}
	if (straight && flush)
	{
		if (straight == 14) return hand(rsf, {});
		else return hand(sf, { straight });
	}
	vi two, three, four;
	REP(i, 13)
	{
		if (rank[i] == 2) two.push_back(i+1);
		if (rank[i] == 3) three.push_back(i+1);
		if (rank[i] == 4) four.push_back(i+1);
	}
	if (four.size() == 1)
	{
		vi v = four;
		if (rank[0] == 1) v.push_back(1);
		for (int i = 12; i > 0; i--)
		{
			if (rank[i] == 1) v.push_back(i + 1);
		}
		REP(i, v.size())
		{
			if (v[i] == 1) v[i] = 14;
		}
		
		return hand(fc, v);
	}
	if (three.size() == 1 && two.size() == 1)
	{
		vi v = { three[0], two[0] };
		REP(i, v.size())
		{
			if (v[i] == 1) v[i] = 14;
		}
		return hand(fh, v);
	}
	vi tmp;
	for (auto i : cards)
	{
		if (i.first == 1) tmp.push_back(14);
		else tmp.push_back(i.first);
	}
	sort(tmp.rbegin(), tmp.rend());
	if (flush) return hand(fl, tmp);
	if (straight) return hand(st, { straight });
	if (three.size() == 1)
	{
		vi v = three;
		if (rank[0] == 1) v.push_back(1);
		for (int i = 12; i > 0; i--)
		{
			if (rank[i] == 1) v.push_back(i + 1);
		}
		REP(i, v.size())
		{
			if (v[i] == 1) v[i] = 14;
		}
		return hand(tc, v);
	}
	if (two.size() == 2)
	{
		sort(two.rbegin(), two.rend());
		vi v = two;
		if (v[1] == 1) swap(v[0], v[1]);
		if (rank[0] == 1) v.push_back(1);
		for (int i = 12; i > 0; i--)
		{
			if (rank[i] == 1) v.push_back(i + 1);
		}
		REP(i, v.size())
		{
			if (v[i] == 1) v[i] = 14;
		}
		return hand(tp, v);
	}
	if (two.size() == 1)
	{
		vi v = two;
		if (rank[0] == 1) v.push_back(1);
		for (int i = 12; i > 0; i--)
		{
			if (rank[i] == 1) v.push_back(i + 1);
		}
		REP(i, v.size())
		{
			if (v[i] == 1) v[i] = 14;
		}
		return hand(op, v);
	}
	return hand(hc, tmp);
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	init();
	vs v(7);
	while (cin >> v[0], v[0] != "#")
	{
		set<card> used;
		REP(i, 6) cin >> v[i + 1];
		vector<card> my_cards, op_cards;
		REP(i, 2) my_cards.push_back(parse(v[i]));
		REP(i, 2) op_cards.push_back(parse(v[i+2]));
		REP(i, 3)
		{
			my_cards.push_back(parse(v[i + 4]));
			op_cards.push_back(parse(v[i + 4]));
		}
		REP(i, 5)
		{
			used.insert(my_cards[i]);
			used.insert(op_cards[i]);
		}
		int cnt = 0, cnt2 = 0;
		REP(suit1, 4)FOR(num1, 1, 14)REP(suit2, 4)FOR(num2, 1, 14)
		{
			if (suit1 == suit2 && num1 == num2) continue;
			card c1(num1, suit1), c2(num2, suit2);
			if (used.count(c1) || used.count(c2)) continue;
			vector<card> t_my = my_cards;
			vector<card> t_op = op_cards;
			t_my.push_back(c1); t_my.push_back(c2);
			t_op.push_back(c2); t_op.push_back(c1);
			hand my_hand(hc, {}), op_hand(hc, {});
			for (auto use : pat)
			{
				vector<card> t_my_cards;
				vector<card> t_op_cards;
				for (auto i : use)
				{
					t_my_cards.push_back(t_my[i]);
					t_op_cards.push_back(t_op[i]);
				}
				sort(ALL(t_my_cards));
				sort(ALL(t_op_cards));
				chmax(my_hand, calc(t_my_cards));
				chmax(op_hand, calc(t_op_cards));
			}
			if (my_hand > op_hand) cnt++;
			cnt2++;
		}
		cout << (ld)cnt / cnt2 << endl;
	}
	return 0;
}