#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
struct card{
	char suit;
	int rank;
	void input()
	{
		cin>>suit;
		char A;cin>>A;
		if(A=='A')rank=1;
		else if(A=='K')rank=13;
		else if(A=='Q')rank=12;
		else if(A=='J')rank=11;
		else if(A=='T')rank=10;
		else rank=A-'0';
	}
	bool operator==(const card&a){return suit==a.suit&&rank==a.rank;}
}A[2],B[2],C[5];
pair<int,vector<int> >calc(vector<card>X)
{
	pair<int,vector<int> >ret=make_pair(-1,vector<int>(0));
	for(int _=0;_<2;_++)
	{
		for(int i=0;i<5;i++)
		{
			if(X[i].rank==1)X[i].rank=14;
			else if(X[i].rank==14)X[i].rank=1;
		}
		bool Flush=true;
		for(int i=1;i<5;i++)if(X[0].suit!=X[i].suit)Flush=false;
		vector<int>tmp(5);
		for(int i=0;i<5;i++)tmp[i]=X[i].rank;
		sort(tmp.begin(),tmp.end());
		reverse(tmp.begin(),tmp.end());
		vector<pair<int,int> >Y;
		for(int i=0;i<5;i++)
		{
			if(i==0||Y.back().first!=tmp[i])Y.push_back(make_pair(tmp[i],1));
			else Y.back().second++;
		}
		if(Y.size()==5&&Y[0].first==Y[4].first+4)
		{
			ret=max(ret,make_pair(Flush?8:4,(vector<int>){Y[0].first}));
		}
		else if(Y.size()==2)
		{
			if(Y[0].second>=3)
			{
				ret=max(ret,make_pair(Y[0].second==4?7:6,(vector<int>){Y[0].first,Y[1].first}));
			}
			else if(Y[1].second>=3)
			{
				ret=max(ret,make_pair(Y[1].second==4?7:6,(vector<int>){Y[1].first,Y[0].first}));
			}
		}
		else if(Flush)
		{
			ret=max(ret,make_pair(5,tmp));
		}
		else if(Y.size()==3)
		{
			if(Y[0].second==3)
			{
				ret=max(ret,make_pair(3,(vector<int>){Y[0].first,Y[1].first,Y[2].first}));
			}
			else if(Y[1].second==3)
			{
				ret=max(ret,make_pair(3,(vector<int>){Y[1].first,Y[0].first,Y[2].first}));
			}
			else if(Y[2].second==3)
			{
				ret=max(ret,make_pair(3,(vector<int>){Y[2].first,Y[0].first,Y[1].first}));
			}
			else if(Y[0].second==2&&Y[1].second==2)
			{
				ret=max(ret,make_pair(2,(vector<int>){Y[0].first,Y[1].first,Y[2].first}));
			}
			else if(Y[0].second==2&&Y[2].second==2)
			{
				ret=max(ret,make_pair(2,(vector<int>){Y[0].first,Y[2].first,Y[1].first}));
			}
			else if(Y[1].second==2&&Y[2].second==2)
			{
				ret=max(ret,make_pair(2,(vector<int>){Y[1].first,Y[2].first,Y[0].first}));
			}
		}
		else if(Y.size()==4)
		{
			int id=0;
			while(Y[id].second==1)id++;
			vector<int>tmq;
			tmq.push_back(Y[id].first);
			for(int i=0;i<5;i++)if(tmp[i]!=tmq[0])tmq.push_back(tmp[i]);
			ret=max(ret,make_pair(1,tmq));
		}
		else ret=max(ret,make_pair(0,tmp));
	}
	return ret;
}
bool ok()
{
	pair<int,vector<int> >pa=make_pair(-1,vector<int>(0)),pb=make_pair(-1,vector<int>(0));
	for(int i=0;i<1<<7;i++)
	{
		if(__builtin_popcount(i)!=5)continue;
		vector<card>a,b;
		for(int j=0;j<7;j++)
		{
			if(i>>j&1)
			{
				if(j<5)a.push_back(C[j]),b.push_back(C[j]);
				else if(j==5)a.push_back(A[0]),b.push_back(B[0]);
				else if(j==6)a.push_back(A[1]),b.push_back(B[1]);
			}
		}
		pa=max(pa,calc(a));
		pb=max(pb,calc(b));
	}
	return pa>pb;
}
main()
{
	card tmp;
	while(tmp.input(),tmp.suit!='#')
	{
		A[0]=tmp;A[1].input();
		B[0].input();B[1].input();
		for(int i=0;i<3;i++)C[i].input();
		int all=0,win=0;
		for(int s1=0;s1<4;s1++)for(int r1=1;r1<=13;r1++)
		{
			C[3].suit="SHDC"[s1];C[3].rank=r1;
			if(A[0]==C[3]||A[1]==C[3]||B[0]==C[3]||B[1]==C[3]||C[0]==C[3]||C[1]==C[3]||C[2]==C[3])continue;
			for(int s2=0;s2<4;s2++)for(int r2=1;r2<=13;r2++)
			{
				C[4].suit="SHDC"[s2];C[4].rank=r2;
				if(A[0]==C[4]||A[1]==C[4]||B[0]==C[4]||B[1]==C[4]||C[0]==C[4]||C[1]==C[4]||C[2]==C[4]||C[3]==C[4])continue;
				all++;
				if(ok())win++;
			}
		}
		cout<<fixed<<setprecision(16)<<(double)win/all<<endl;
	}
}



Measured memory_bytes: 3268