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<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}


int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

struct card {
	int suit, rank;
	card(const string&s) {
		suit = string("CDHS").find(s[0]);
		rank = string("0A23456789TJQK").find(s[1]);
	}
	bool operator<(const card& o)const {
		return rank != o.rank ? rank < o.rank : suit < o.suit;
	}
};

card trans(int i) {
	string res;
	int d = i / 13, r = i % 13;
	res.push_back(string("CDHS")[d]);
	res.push_back(string("A23456789TJQK")[r]);
	return card(res);
}
int poker_hand(const vector<card>& hand) {
	vector<int> x(27), y(4);
	for (card i : hand) {
		++x[i.rank]; ++y[i.suit];
		if (i.rank == 1)++x[i.rank + 13];
	}
	bool straight = false;
	for (int i = 1; i + 4 < 27; ++i) {
		if (x[i] && x[i + 1] && x[i + 2] && x[i + 3] && x[i + 4])straight = true;
	}
	x[1] = 0; sort(x.rbegin(), x.rend()); sort(y.rbegin(), y.rend());
	bool flush = (y[0] == 5);
	if (straight)return(flush ? 8 : 4);
	if (flush)return 5;
	if (x[0] == 4)return 7;
	if (x[0] == 3)return (x[1] == 2 ? 6 : 3);
	if (x[0] == 2)return (x[1] == 2 ? 2 : 1);
	return 0;
}

vector<int> sort_hands(const vector<card>& hand, bool ace) {
	int n = hand.size();
	vector<P> v(n);
	rep(i, n) {
		int cnt = 0, num = hand[i].rank;
		for (card c : hand) {
			if (num == c.rank)++cnt;
			v[i] = { cnt,num };
		}
	}
	rep(i, n)if (v[i].second == 1 && ace)v[i].second = 14;
	sort(v.rbegin(), v.rend());
	vector<int> res(n);
	rep(i, n)res[i] = v[i].second;
	return res;
}
int poker(const vector<card>& hand) {
	int a = poker_hand(hand);
	bool flag = ((a != 4 && a != 8) || hand[0].rank > 8 || hand[1].rank > 8);
	vector<int> v = sort_hands(hand, flag);
	int res = (a << 20);
	rep(i, 5)res += (v[i] << ((4 - i) * 4));
	return res;
}

int calc(vector<card>hand) {
	int ma = 0;
	vector<int> v = { 0,0,1,1,1,1,1 };
	while (true) {
		vector<card> t;
		rep(i, v.size())if(v[i])t.push_back(hand[i]);
		ma = max(ma, poker(t));
		if (!next_permutation(all(v)))break;
	}
	return ma;
}
string s[2], t[2], u[3];
void solve() {
	map<card, bool> used;
	rep(i, 2)used[s[i]] = true;
	rep(i, 2)used[t[i]] = true;
	rep(i, 3)used[u[i]] = true;
	int tmp = 0;
	int cnt = 0;
	//cout << poker({ s[0],s[1],u[0],u[1],u[2] }) << endl;
	rep(i, 52) {
		card a = trans(i);
		if (used[a])continue;
		Rep(j,i+1, 52) {
			if (i == j)continue;
			card b = trans(j);
			if (used[b])continue;
			tmp++;
			int le = calc({ s[0],s[1],u[0],u[1],u[2],a,b });
			int ri = calc({ t[0],t[1],u[0],u[1],u[2],a,b });
			//cout << i << " " << j << " " << le << " " << ri << endl;
			if (le > ri)cnt++;
		}
	}
	ld ans = cnt / (ld)tmp;
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(12);
	//init_f(); init();
	while (cin >> s[0]) {
		if (s[0] == "#")break;
		cin >> s[1];
		cin >> t[0] >> t[1];
		cin >> u[0] >> u[1] >> u[2];
		solve();
	}
	//int t; cin >> t; rep(i, t)solve();
	//solve();
	stop
		return 0;
}