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