#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;
}



Measured memory_bytes: 19640