#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

vector<int> phand, ohand;
bool used[52];
int pyaku, oyaku;
vector<int> ptie, otie;

int parse(char c1, char c2)
{
	int ret;
	if(c1 == 'S') ret = 0;
	if(c1 == 'H') ret = 13;
	if(c1 == 'D') ret = 26;
	if(c1 == 'C') ret = 39;
	
	if(c2 == 'A') ret += 0;
	else if(c2 == 'K') ret += 12;
	else if(c2 == 'Q') ret += 11;
	else if(c2 == 'J') ret += 10;
	else if(c2 == 'T') ret += 9;
	else ret += c2 - '0' - 1;
	
	used[ret] = true;
	return ret;
}

int suit(int x){
	return x / 13;
}
int rank(int x){
	return x % 13;
}

bool comp(int &yaku1, vector<int> &tie1, int &yaku2, vector<int> &tie2)
{
	if(yaku1 > yaku2) return true;
	if(yaku1 == yaku2){
		for(int k = 0; k < tie1.size(); k++){
			if(tie1[k] > tie2[k]) return true;
			else if(tie1[k] < tie2[k]) return false;
		}
	}
	return false;
}

void judge(vector<int> &hand, int &yaku, vector<int> &tie)
{
	tie.clear();
	vector<int> use;
	int cnt[15];
	multiset<int> s;
	
	int cyaku = -1, nyaku;
	vector<int> ctie, ntie;
	for(int i = 0; i < 5; i++){
		ctie.push_back(-1);
	}
	
	for(int i = 0; i < 7; i++){
		for(int j = 0; j < 7; j++){
			if(i >= j) continue;
			
			//cout << i << " " << j << endl;
			
			use.clear();
			for(int k = 0; k < 7; k++){
				if(k != i && k != j) use.push_back(hand[k]);
			}
			
			vector<int> rvec;
			for(int k = 0; k < 5; k++) rvec.push_back(rank(use[k]));
			sort(rvec.begin(), rvec.end());
			
			bool flash = true;
			for(int k = 0; k < 5; k++){
				if(suit(use[k]) != suit(use[0])){
					flash = false;
					break;
				}
			}
			bool straight = true;
			for(int k = 0; k < 5; k++){
				if(rvec[k] != rvec[0]+k){
					straight = false;
					break;
				}
			}
			bool hi_straight = false;
			if(rvec[0] == 0 && rvec[1] == 9 && rvec[2] == 10 && rvec[3] == 11 && rvec[4] == 12){
				hi_straight = true;
			}
			
			ntie.clear();
			if(hi_straight && flash){
				nyaku = 9;
				for(int k = 13; k >= 9; k--) ntie.push_back(k);
				goto end;
			}
			if(straight && flash){
				nyaku = 8;
				for(int k = 4; k >= 0; k--) ntie.push_back(rvec[k]);
				goto end;
			}
			if(straight){
				nyaku = 4;
				for(int k = 4; k >= 0; k--) ntie.push_back(rvec[k]);
				goto end;
			}
			if(hi_straight){
				nyaku = 4;
				for(int k = 13; k >= 9; k--) ntie.push_back(k);
				goto end;
			}
			
			for(int k = 0; k < 5; k++) if(rvec[k] == 0) rvec[k] = 13;
			sort(rvec.begin(), rvec.end());
			
			for(int k = 0; k <= 13; k++) cnt[k] = 0;
			for(int k = 0; k < 5; k++) cnt[rvec[k]]++;
			s.clear();
			for(int k = 0; k <= 13; k++) s.insert(cnt[k]);
			
			if(s.count(4)){
				nyaku = 7;
				for(int k = 0; k <= 13; k++) if(cnt[k] == 4) ntie.push_back(k);
				for(int k = 0; k <= 13; k++) if(cnt[k] == 1) ntie.push_back(k);
				goto end;
			}
			if(s.count(2) && s.count(3)){
				nyaku = 6;
				for(int k = 0; k <= 13; k++) if(cnt[k] == 3) ntie.push_back(k);
				for(int k = 0; k <= 13; k++) if(cnt[k] == 2) ntie.push_back(k);
				goto end;
			}
			if(flash){
				nyaku = 5;
				for(int k = 13; k >= 0; k--) if(cnt[k] == 1) ntie.push_back(k);
				goto end;
			}
			if(s.count(3)){
				nyaku = 3;
				for(int k = 0; k <= 13; k++) if(cnt[k] == 3) ntie.push_back(k);
				for(int k = 13; k >= 0; k--) if(cnt[k] == 1) ntie.push_back(k);
				goto end;
			}
			if(s.count(2) == 2){
				nyaku = 2;
				for(int k = 13; k >= 0; k--) if(cnt[k] == 2) ntie.push_back(k);
				for(int k = 13; k >= 0; k--) if(cnt[k] == 1) ntie.push_back(k);
				goto end;
			}
			if(s.count(2)){
				nyaku = 1;
				for(int k = 13; k >= 0; k--) if(cnt[k] == 2) ntie.push_back(k);
				for(int k = 13; k >= 0; k--) if(cnt[k] == 1) ntie.push_back(k);
				goto end;
			}
			nyaku = 0;
			for(int k = 13; k >= 0; k--) if(cnt[k] == 1) ntie.push_back(k);
			
			end:;
			if(comp(nyaku, ntie, cyaku, ctie)){
				cyaku = nyaku, ctie = ntie;
			}
			
			/*for(int k = 0; k < use.size(); k++) cout << use[k] << " "; cout << endl;
			cout << "[" << nyaku << "] "; for(int k = 0; k < ntie.size(); k++) cout << ntie[k] << " "; cout << endl;
			cout << endl;*/
		}
	}
	
	yaku = cyaku, tie = ctie;
}

int main(void)
{
	char c1, c2;
	while(1){
		phand.clear();
		ohand.clear();
		for(int i = 0; i < 52; i++) used[i] = false;
		
		cin >> c1; if(c1 == '#') break;
		cin >> c2;
		phand.push_back(parse(c1, c2));
		cin >> c1 >> c2;
		phand.push_back(parse(c1, c2));
		cin >> c1 >> c2;
		ohand.push_back(parse(c1, c2));
		cin >> c1 >> c2;
		ohand.push_back(parse(c1, c2));
		
		for(int i = 0; i < 3; i++){
			cin >> c1 >> c2;
			phand.push_back(parse(c1, c2));
			ohand.push_back(parse(c1, c2));
		}
		
		int all_cnt = 0, win_cnt = 0;
		for(int i = 0; i < 52; i++){
			if(used[i]) continue;
			for(int j = 0; j < 52; j++){
				if(i >= j) continue;
				if(used[j]) continue;
				
				//cout << "*" << i << " " << j << endl;
				
				phand.push_back(i), phand.push_back(j);
				ohand.push_back(i), ohand.push_back(j);
				
				judge(phand, pyaku, ptie);
				judge(ohand, oyaku, otie);
				
				/*cout << "Player" << endl;
				for(int k = 0; k < phand.size(); k++) cout << phand[k] << " "; cout << endl;
				cout << "[" << pyaku << "] "; for(int k = 0; k < ptie.size(); k++) cout << ptie[k] << " "; cout << endl;
				cout << endl;
				
				cout << "Opponent" << endl;
				for(int k = 0; k < ohand.size(); k++) cout << ohand[k] << " "; cout << endl;
				cout << "[" << oyaku << "] "; for(int k = 0; k < otie.size(); k++) cout << otie[k] << " "; cout << endl;
				cout << endl;*/
				
				all_cnt++;
				if(comp(pyaku, ptie, oyaku, otie)) win_cnt++;//, cout << "Win" << endl << endl;
				
				phand.erase(phand.end()-1),phand.erase(phand.end()-1);
				ohand.erase(ohand.end()-1),ohand.erase(ohand.end()-1);
			}
		}
		//cout << win_cnt << " " << all_cnt << endl;
		
		printf("%.11f\n", (double)win_cnt / (double)all_cnt);
	}
	
	return 0;
}


Measured memory_bytes: 3220