#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
char str[7][5];
long long OP=1000000000LL;
long long TP=2000000000LL;
long long TC=3000000000LL;
long long ST=4000000000LL;
long long FL=5000000000LL;
long long FH=6000000000LL;
long long FC=7000000000LL;
long long SF=8000000000LL;
long long RF=9000000000LL;
int v[5];
long long yk(vector<int>c){
	std::sort(c.begin(),c.end());
	bool flash=false;
	bool royal=false;
	if(c[0]%4==c[1]%4&&c[0]%4==c[2]%4&&c[0]%4==c[3]%4&&c[0]%4==c[4]%4)flash=true;
	for(int i=0;i<5;i++)c[i]/=4;
	if(c[0]==0&&c[1]==9&&c[2]==10&&c[3]==11&&c[4]==12)royal=true;
	for(int i=0;i<5;i++)v[i]=0;
	long long sc=0;
	int rem=5;
	while(rem){
		sc*=14;
		int sh=0;
		int val=-1;
		int best=0;
		int bval=0;
		for(int i=0;i<5;i++){
			if(v[i])continue;
			if(c[i]==val){
				sh++;
			}else {
				val=c[i];sh=1;
			}
			if(best<sh||(best==sh&&(c[i]==0||bval<c[i]))){
				best=sh;
				bval=c[i];
				if(bval==0)bval=13;
			}
		}
		sc+=bval;
		for(int i=0;i<5;i++){
			if(!v[i]&&bval%13==c[i]){
				v[i]=1;rem--;
			}
		}
	}
	bool stra=true;
	for(int i=1;i<5;i++)if(c[i]!=c[i-1]+1)stra=false;
	if(royal&&flash)return RF;
	if(flash&&stra)return SF+c[4];
	if(c[0]==c[3]||c[1]==c[4])return FC+sc;
	if((c[0]==c[2]&&c[3]==c[4])||(c[0]==c[1]&&c[2]==c[4]))return FH+sc;
	if(flash)return FL+sc;
	if(royal){
		return ST+114514;
	}
	if(stra)return ST+c[4];
	if(c[0]==c[2]||c[1]==c[3]||c[2]==c[4])return TC+sc;
	if((c[0]==c[1]&&c[2]==c[3])||(c[0]==c[1]&&c[3]==c[4])||(c[1]==c[2]&&c[3]==c[4]))return TP+sc;
	if(c[0]==c[1]||c[1]==c[2]||c[2]==c[3]||c[3]==c[4])return OP+sc;
	return sc;
}
bool used[55];
int p[7];
int perm[8];
int main(){
	while(1){
		scanf("%s",str[0]);
		if(str[0][0]=='#')break;
		for(int i=1;i<7;i++)scanf("%s",str[i]);
		for(int i=0;i<55;i++)used[i]=false;
		for(int i=0;i<7;i++){
			int tmp=0;
			if(str[i][1]=='T')tmp=9;
			if(str[i][1]=='J')tmp=10;
			if(str[i][1]=='Q')tmp=11;
			if(str[i][1]=='K')tmp=12;
			if('2'<=str[i][1]&&str[i][1]<='9')tmp=str[i][1]-'1';
			tmp*=4;
			if(str[i][0]=='S')tmp+=3;
			if(str[i][0]=='H')tmp+=2;
			if(str[i][0]=='D')tmp++;
			p[i]=tmp;
			used[p[i]]=1;
		}
		int win=0;
		int tot=0;
		for(int i=0;i<52;i++)for(int j=0;j<52;j++){
			if(used[i]||used[j]||i==j)continue;
			perm[0]=perm[1]=0;
			for(int k=2;k<7;k++)perm[k]=1;
			long long A=0;
			long long B=0;
			do{
				vector<int>t;
				for(int k=0;k<7;k++)if(perm[k]){
					if(k<2)t.push_back(p[k]);
					else if(k<5)t.push_back(p[k+2]);
					else if(k==6)t.push_back(i);
					else t.push_back(j);
				}
				long long Y=yk(t);
		//		printf("%lld\n",Y);
				A=max(A,Y);
			}while(next_permutation(perm,perm+7));
			do{
				vector<int>t;
				for(int k=0;k<7;k++)if(perm[k]){
					if(k<2)t.push_back(p[k+2]);
					else if(k<5)t.push_back(p[k+2]);
					else if(k==6)t.push_back(i);
					else t.push_back(j);
				}
				long long Y=yk(t);
		//		printf("%lld\n",Y);
				B=max(B,Y);
			}while(next_permutation(perm,perm+7));
			if(A>B)win++;
			tot++;
		}
		printf("%.12f\n",(double)win/tot);
	}
}