#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 4

enum Type{
	S,
	H,
	D,
	C,
};

enum Hands{
	Undefined,
	None,
	OnePair,
	TwoPair,
	ThreeCard,
	Straight,
	Flush,
	FullHouse,
	FourCard,
	StraightFlush,
	Royal,
};

struct Info{
	Info(){
		type = S;
		number = 0;
	}
	Info(Type arg_type,int arg_number){
		type = arg_type;
		number = arg_number;
	}
	void set(Type arg_type,int arg_number){
		type = arg_type;
		number = arg_number;
	}
	bool operator<(const struct Info &arg) const{ //数字の昇順
		return number < arg.number;
	}
	Type type;
	int number;
};

int table_index;
bool check[4][14];
bool table[21][7];
char me[2][NUM],enemy[2][NUM],common[3][NUM];
Info me_cards[7],enemy_cards[7];
Type type_array[4] = {S,H,D,C};
Hands me_hands,enemy_hands;
vector<int> me_comp,enemy_comp;
vector<Info> V;



Info read_func(char buf[NUM]){
	Info ret;

	Type type;

	switch(buf[0]){
	case 'S':
		type = S;
		break;
	case 'H':
		type = H;
		break;
	case 'D':
		type = D;
		break;
	case 'C':
		type = C;
		break;
	}

	int num;
	if(buf[1] >= '0' && buf[1] <= '9'){

		num = buf[1]-'0';

	}else{

		switch(buf[1]){
		case 'T':
			num = 10;
			break;
		case 'J':
			num = 11;
			break;
		case 'Q':
			num = 12;
			break;
		case 'K':
			num = 13;
			break;
		case 'A':
			num = 1;
			break;
		}
	}

	ret.set(type,num);
	check[type][num] = true;

	return ret;
}

int calc(int num){

	if(num != 1){
		return num;
	}else{
		return 14;
	}
}

vector<int> make_comp(vector<Info> work,Hands tmp_hands,int num_check[14]){

	vector<int> ret;

	switch(tmp_hands){
	case Royal:
		//Do nothing
		break;
	case StraightFlush:
		ret.push_back(work[4].number); //★★Aが末尾ならロイヤルになるので、Aが末尾ではない★★
		break;
	case FourCard:

		for(int i = 1; i <= 13; i++){
			if(num_check[i] == 4){
				ret.push_back(calc(i));
				break;
			}
		}
		for(int i = 1; i <= 13; i++){
			if(num_check[i] == 1){
				ret.push_back(calc(i));
				break;
			}
		}
		break;
	case FullHouse:
		for(int i = 1; i <= 13; i++){
			if(num_check[i] == 3){
				ret.push_back(calc(i));
				break;
			}
		}
		for(int i = 1; i <= 13; i++){
			if(num_check[i] == 2){
				ret.push_back(calc(i));
				break;
			}
		}
		break;
	case Flush:

		for(int i = 0; i < num_check[1]; i++){
			ret.push_back(14);
		}
		for(int i = 13; i >= 2; i--){ //降順にpush
			for(int k = 0; k < num_check[i]; k++){
				ret.push_back(calc(i));
			}
		}

		break;
	case Straight:

		if(work[0].number == 1 && work[1].number == 10){

			ret.push_back(14);

		}else{
			ret.push_back(work[4].number);
		}

		break;
	case ThreeCard:

		for(int i = 1; i <= 13; i++){
			if(num_check[i] == 3){
				ret.push_back(calc(i));
				break;
			}
		}
		if(num_check[1] == 1){
			ret.push_back(14);
		}
		for(int i = 13; i >= 2; i--){
			if(num_check[i] == 1){
				ret.push_back(calc(i));
			}
		}
		break;
	case TwoPair:
		if(num_check[1] == 2){
			ret.push_back(14);
		}
		for(int i = 13; i >= 2; i--){
			if(num_check[i] == 2){
				ret.push_back(i);
			}
		}
		if(num_check[1] == 1){
			ret.push_back(14);
		}else{
			for(int i = 13; i >= 2; i--){
				if(num_check[i] == 1){
					ret.push_back(i);
					break;
				}
			}
		}
		break;
	case OnePair:
		if(num_check[1] == 2){
			ret.push_back(14);
		}else{
			for(int i = 13; i >= 2; i--){
				if(num_check[i] == 2){
					ret.push_back(i);
					break;
				}
			}
		}
		if(num_check[1] == 1){
			ret.push_back(14);
		}
		for(int i = 13; i >= 2; i--){
			if(num_check[i] == 1){
				ret.push_back(i);
			}
		}

		break;
	case None:
		if(num_check[1] == 1){
			ret.push_back(14);
		}
		for(int i = 13; i >= 2; i--){
			if(num_check[i] == 1){
				ret.push_back(i);
			}
		}
		break;
	}

	return ret;
}

bool is_straight(vector<Info> work){

	if(work[0].number+4 == work[4].number){

		return true;
	}else if(work[0].number == 1 && work[1].number == 10 && work[2].number == 11 && work[3].number == 12 && work[4].number == 13){
		return true;
	}else{
		return false;
	}
}

void calc_hands(vector<Info> work,bool is_me){

	Hands tmp_hands = Undefined,current_hands;
	if(is_me){
		current_hands = me_hands;
	}else{
		current_hands = enemy_hands;
	}

	int suit_check[4],num_check[14];
	for(int i = 0; i < 4; i++){
		suit_check[i] = 0;
	}
	for(int i = 1; i <= 13; i++){
		num_check[i] = 0;
	}

	sort(work.begin(),work.end()); //★昇順sort★

	for(int i = 0; i < 5; i++){
		suit_check[work[i].type]++;
		num_check[work[i].number]++;
	}

	priority_queue<int> num_Q;


	int max_suit_count = 0,max_num_count = 0,second_num_count = 0;

	for(int i = 0; i < 4; i++){
		max_suit_count = max(max_suit_count,suit_check[i]);
	}
	for(int i = 1; i <= 13; i++){
		num_Q.push(num_check[i]);
	}

	max_num_count = num_Q.top();
	num_Q.pop();
	second_num_count = num_Q.top();

	if(max_suit_count == 5){ //フラッシュ

		if(is_straight(work)){

			if(work[0].number == 1 && work[1].number == 10){
				tmp_hands = Royal;
			}else{
				tmp_hands = StraightFlush;
			}

		}else{

			if(max_num_count == 4){
				tmp_hands = FourCard;
			}else if(max_num_count == 3 && second_num_count == 2){
				tmp_hands = FullHouse;
			}else{
				tmp_hands = Flush;
			}
		}

	}else{

		if(max_num_count == 4){
				tmp_hands = FourCard;
		}else if(max_num_count == 3){

			if(second_num_count == 2){
				tmp_hands = FullHouse;
			}else{
				tmp_hands = ThreeCard;
			}

		}else if(max_num_count == 2){

			if(second_num_count == 2){
				tmp_hands = TwoPair;
			}else{
				tmp_hands = OnePair;
			}

		}else{ //max_num_count == 1

			if(is_straight(work)){
				tmp_hands = Straight;
			}else{
				tmp_hands = None;
			}
		}
	}


	if(tmp_hands < current_hands){
		//Do nothing
	}else if(tmp_hands > current_hands){
		//最強手更新
		if(is_me){
			me_hands = tmp_hands;
		}else{
			enemy_hands = tmp_hands;
		}
		vector<int> tmp_comp = make_comp(work,tmp_hands,num_check); //比較用配列更新

		if(is_me){

			me_comp.clear();
			me_comp = tmp_comp;

		}else{

			enemy_comp.clear();
			enemy_comp = tmp_comp;

		}

	}else{ //tmp_hands == current_hands

		//比較用配列を作り、既存の物と比べ、強い方を採用する
		vector<int> tmp_comp = make_comp(work,tmp_hands,num_check);

		bool is_stronger = false;

		for(int i = 0; i < tmp_comp.size(); i++){
			if(is_me){
				if(tmp_comp[i] != me_comp[i]){
					is_stronger = (tmp_comp[i] > me_comp[i]);
					break;
				}
			}else{
				if(tmp_comp[i] != enemy_comp[i]){
					is_stronger = (tmp_comp[i] > enemy_comp[i]);
					break;
				}
			}
		}

		if(is_stronger){
			if(is_me){

				me_comp.clear();
				me_comp = tmp_comp;

			}else{

				enemy_comp.clear();
				enemy_comp = tmp_comp;

			}
		}
	}
}

void debug(Info info){

	switch(info.type){
	case S:
		printf("S");
		break;
	case H:
		printf("H");
		break;
	case D:
		printf("D");
		break;
	case C:
		printf("C");
		break;
	}
	printf("%d\n",info.number);
}

void func(){

	V.clear();

	for(int i = 0; i < 4; i++){
		for(int k = 1; k <= 13; k++){
			check[i][k] = false;
		}
	}

	scanf("%s",me[1]);
	scanf("%s %s",enemy[0],enemy[1]);
	scanf("%s %s %s",common[0],common[1],common[2]);

	for(int i = 0; i < 2; i++){
		me_cards[i] = read_func(me[i]);
	}
	for(int i = 0; i < 2; i++){
		enemy_cards[i] = read_func(enemy[i]);
	}
	for(int i = 0; i < 3; i++){
		me_cards[2+i] = read_func(common[i]);
		enemy_cards[2+i] = me_cards[2+i];
	}

	for(int suit = 0; suit < 4; suit++){
		for(int num =1; num <= 13; num++){
			if(check[suit][num])continue;

			V.push_back(Info(type_array[suit],num));
		}
	}

	int count = 0;
	bool FLG;

	vector<Info>me_work,enemy_work;

	//残りのカードの組合せを全探索
	for(int i = 0; i < V.size()-1; i++){
		for(int k = i+1; k < V.size(); k++){

			me_cards[5] = V[i];
			me_cards[6] = V[k];

			enemy_cards[5] = V[i];
			enemy_cards[6] = V[k];

			me_comp.clear();
			enemy_comp.clear();

			me_hands = Undefined;
			enemy_hands = Undefined;

			//meの最強手を探す
			for(int a = 0; a < table_index; a++){ //7C5 全探索
				me_work.clear();
				for(int b = 0; b < 7; b++){
					if(!table[a][b])continue;
					me_work.push_back(me_cards[b]);
				}
				calc_hands(me_work,true);
			}

			//enemyの最強手を探す
			for(int a = 0; a < table_index; a++){
				enemy_work.clear();
				for(int b = 0; b < 7; b++){
					if(!table[a][b])continue;
					enemy_work.push_back(enemy_cards[b]);
				}
				calc_hands(enemy_work,false);
			}

			//比較
			if(me_hands > enemy_hands){
				count++;
			}else if(me_hands < enemy_hands){
				//Do nothing
			}else{

				FLG = false;

				for(int i = 0; i < me_comp.size(); i++){
					if(me_comp[i] != enemy_comp[i]){
						if(me_comp[i] > enemy_comp[i]){
							count++;
						}
						FLG = true;
						break;
					}
				}

				if(!FLG){ //同点:負け扱い
					//Don nothing
				}
			}
		}
	}

	printf("%.10lf\n",(double)count/(double)(45*44/2));
}

void makeTable(){

	table_index = 0;

	for(int left = 0; left <= 5; left++){
		for(int right = left+1; right <= 6; right++){
			for(int i = 0; i <= 6; i++)table[table_index][i] = true;
			table[table_index][left] = false;
			table[table_index][right] = false;
			table_index++;
		}
	}

}

int main(){

	makeTable();

	while(true){
		scanf("%s",me[0]);
		if(me[0][0] == '#')break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3196