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:
/*
 *                             UM.
 *                            J@B@1                                                                    iO@1
 *                           Y@@@B@BB.                                                              7B@B@B@
 *                          :@B@i,B@B@O                                                          ,Z@B@B@B@Br
 *                          @B@q   i@B@BS                                                      7@B@@@O5vMB@q
 *                         8@@B      LB@B@i                                                  FB@@@BNjYjLE@B@
 *                        ,B@B:        0@@@Z                                               P@B@BM1JJ125JPB@B
 *                        B@BB          :@B@B                                            XB@B@Z2LuU52F2u2@B@.
 *                       :@B@             @@@B:                                        v@B@B8uJj51F1525uUB@B7
 *                       @B@O              0@@B.               ..::ir7vvYUuU777r::.   B@B@OULU2F2F151F11Y@B@S
 *                       B@B,               8B@B  :ruXMB@B@B@B@B@B@B@B@B@B@@@B@B@B@B@B@B@5Jj1211F1F1F2FUJO@BB
 *                      U@B@                 @B@B@B@B@B@@@B@B@B@MMqPS5JuYL7rq@B@OBB@B@B8Yu211F1515251515YGB@@
 *                      @B@u                 v@@@@MSur:.                    LB@MvvjJuU5YU252F1F1F25251F2uX@@@
 *                      @@@.                                                N@BML2U2UUU12F15252525251515Jk@@B
 *                     r@B@                                                 YB@Bju52121252515252F15251F2u5@B@
 *                     PB@B                                                  @@@PYUF151F25151F152F2F1F15jF@@B
 *                     @@BS                                                  N@@@UJ2F25252F251525151F1F1u5@B@
 *                     @@@7                                                   B@B@5Yj12F152F1F1F25252515jFB@B
 *                     B@Bi                                                    M@B@O2Luu52525212F151121UY1@B@7
 *                    O@B@:                                                     v@B@BMSuYJJuuUu2u2uujjYJJXB@B@M
 *                  7B@B@,                                                        1B@@@B@GPF1uujuu21PNMB@B@B@B@@
 *                 qB@B2                                                            i8B@B@B@B@B@@@@@B@B@B@q: @@@B
 *                MB@B:                                                                 7SBB@B@B@B@B@Zu:      @B@B
 *               ZB@B.                                              ,v.                                        @B@L
 *              LB@B,                         Y7                    @B@Bu                                      7@B@
 *   :B@B@@B2:  @@B7                         @B@Z                   r@B@B@BP:                                   B@BE
 *    BB@@@B@B@B@BE                        r@B@B                       7@B@B@B@Ou:                              iB@B
 *         :uM@@B@@2.           :7::::ivk@B@B@0                           :5B@B@B@B@B@B@G.                       @B@i
 *            BB@@@B@@         :@B@B@@@B@B@@1                                 .i5M@B@B@@@5                       M@@2
 *            B@B ,@B1          L0EZZG0F7:                                            .:,                        uB@MrP@M7
 *           2@B@                                                                                               ,O@B@B@B@B
 *           @B@1                                                     :@B@@@r                                :@@@@B@BL:,,
 *           B@Bi                         :2ZS;                      :@B@B@B@r                               L@B@B@BU
 *           @B@.                        @@@B@B@                     vB@B@B@B5                                   @B@i
 *           B@B                        7B@B@B@BM                     OB@B@B@                                   ,B@B
 *           @B@                         @B@B@@@i                       rL7.                                    B@BM
 *           B@B7.:                       NB@@M.                                                               .@B@.
 *  .;JEB@@@B@B@B@B@.                                                                                       .  @B@u
 *@@@B@B@B@B@@@B@18U                                                                                      :B@B@B@BU,
 *7@BOui.    ,@@B                                                                                          SP@B@B@B@B@Or
 *            @@@U                                                                                           B@BJ.YO@B@B@i
 *            r@B@                                                                                         :B@Bk     .k@B@
 *             B@B@                                                                                       LB@@k         2i
 *              B@BM                                      .7jXEGqF7:                                     OB@@L
 *              .B@BM                                   .B@B@B@B@B@B@.                                 :@B@B:
 *               .B@B@                                   @@MYr::ivG@B                                .M@B@G
 *                 B@@@S                                                                           ,MB@B@,
 *                  v@@@BF                                                                      .1B@B@Br
 *                    2@@B@BL                                                                ,FB@@@B8,
 *                      r@B@B@BF,                                                        :YBB@B@B@B
 *                         L@B@B@B@P7,                                           .ivXB@B@B@B@B@M@B@
 *                            ,1B@B@B@B@@@BOP2L7i:,.              ..,:i7LSNB@@B@B@@@B@B@B@Z5v;.LB@@
 *                              @B@OEB@B@@@B@B@B@B@B@B@B@B@@@B@B@B@B@B@@@B@B@B@B@BM0SJ7i::::i:,u@B@
 *                              B@Bu ::i;7vu2XNGOMB@B@BMB@B@B@B@B@B@@@B1UFuj77ii:::::::iir;r;i.YB@B
 *                              @B@L.:i:i:i::::::::::..Y@B@BMYi:i;SB@B@N:.::i:iirir;r;rii::::ivO@B@
 *                              B@@X::,::::iirir;riri:E@B@1         ,@B@Br:;;r;rii:i::::i7JEB@@@@@B
 *                              @@@B@BBq5v7ii:::::::.2@@@i  ..,..     @B@@,,:::::irv2XMB@B@B@B@2@B@:
 *                             .B@BBB@@@B@B@B@BMNP5u7@B@1 .,,:,,  :.   @B@P50MB@B@B@B@B@@@BS:   @@B1
 *                             E@B@   ijGB@B@B@B@B@B@B@Bi .,:,,..@@B@7 B@B@B@B@B@B@BM57.        kB@B
 *                            .@B@:          .,ivu5Nq@B@u  ..,.. SB@B@@@B@PL7i,                 ,@B@
 *                            @@@8                   i@B@:    .     :B@B@@                       B@@2
 *                          i@@@@                     0@B@u          B@@B.                       vB@B
 *                         ,@B@G                       L@B@BOv:.:iFB@B@M                          @B@Bi
 *                          vNi                          S@@B@B@B@B@BM:                            MB@N
 *                                                          758BMqJ,
 *
 *                 .  YO.               vq                            :G       Z:
 *        SqOMBB@B@Br @@r rBE           @B     B@@@@@B@ONX8k    i::::.OB1.:::.u@O.::::i           @B@B@U:@@B@@BPEBu
 *        B@@NB@k.    5@i  uB@E.        BM     1U2uUJvirB@@Z   r@@B@B@@@B@B@B@B@B@@@B@Bi   LB@B@1 BX :@k uLLLvr@BJ:
 *            iB      iBi    7@     .@M8@BGMZZ         @@F            ,B       Pi          v@  Bq @i v@        B@
 *       vuL7r8@S7vJL7N@Z7LLri;72.   F7@Bvvv@@       @BX         @@@B@B@@@@@B@@@B@B@B      7@  @F Bi @q  @B@Bu @B
 *       N@B@G@@@8@BBOMB@G@BMNXG@,     B@   @@      .Bk          .:u;    i@:      Zv       7@  Bk @,;@  ,BY @B B@
 *            r@       @G     5.      ,@v   BZ :::,.r@E .::i,      @B     B@    .@BL       7@  @F B:i@. .@  @M @B
 *            7B: ,vO, @@   iB@:      @B   7@:MB@B@B@@@B@B@BM       @@.    B:  2@q         7@  BS @i 0@  B. @O B@
 *       ,r2EBB@B@B@Bi G@  @BB        B@   @B        @S              :    r@   ..          7B  @F @7  B7 @  @B @B
 *       E@B@UOBr       @B@Bi          L@0PB        .BZ        .@B@B@B@B@B@B@B@B@B@B@B@,   r@  BF @i  @G B@B@B B@
 *            7@,      kB@U    ;r        @@@.       .@Z                GBuL@iBBi           vB@B@q BP:5@7 @u,.  @B
 *            LBi   YB@BrB@    @@       @B:L@Br      BM             .M@B  rB  rB@J         v@. Pi @XZ8r  .     B@
 *        .   G@i B@BM.  ,B@,  @B    iB@B    N, 7r..q@k         ,LB@B8    J@,   i@B@B1r           Br           @@
 *        MB@B@B  ,i       B@B@B,    B@:        @B@B@F         .@BB:      P@i      :OBZ          .@U       B@B@B:
 *                          .ll                                           rB.                     :
 */
/*****************
 *   I<3   C++   *
 *  IWANT ANYAC  *
 * ILOVEPROGRAM! *
 *IT'SINTERESTING*
 * ILOVEPROGRAM! *
 *  INCONTESTS   *
 *   GETSCORE    *
 *    ACCODE     *
 *     LETS      *
 *      GO       *
 *Written by:    *
 *    charlieyan *
 *****************/
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#include <numeric>
#include <list>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define FILLBIG(a) FILL(a,0x7f)
#define ALL(a) (a).begin(),(a).end()
#define Inf ((int)0x7f7f7f7f)
#define INF ((long long)0x7f7f7f7f7f7f7f7f)
#define Mod 1000000007
#define foreach(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define MASK(a) (1<<(a))
#define MASKX(x,a) ((x)<<(a))
#define BIT(a,b) ((a>>b)&1)
#define cddx(a) priority_queue<a >
#define cxdd(a) priority_queue<a,vector<a >,greater<a > >
#define deval(a) {cerr<<#a<<" = "<<a<<endl;}
#define dearr(be,en) {cerr<<#be;cerr<<" = {";for(auto i=be;i!=en;i++)cerr<<' '<<*i;cerr<<" }\n";}
#define reg register
#define prtime eprintf("\n\nTime used: %dms\n",clock());
#define PI 3.1415926535897932384626
#define TODEG(a) (a*180/PI)
//Союз советских социалистических республик
//苏维埃社会主义共和国联盟
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int uint;
typedef long long INT;
typedef long double ldouble;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;
inline int read()
{
	int num=0;
	char c=getchar();
	if(c=='-')return -read();
	while(c>='0'&&c<='9')
	{
		num=(num<<3)+(num<<1)+c-'0';
		c=getchar();
	}
	return num;
}
inline INT READ()
{
	INT num=0;
	char c=getchar();
	if(c=='-')return -READ();
	while(c>='0'&&c<='9')
	{
		num=(num<<3)+(num<<1)+c-'0';
		c=getchar();
	}
	return num;
}
//Coded by Charlieyan
//版权所有，翻印必究

int mc1,mc2,oc1,oc2,sc1,sc2,sc3;
int sc4,sc5;
int hvm[57],hvo[57],hvnm[17],hvno[17],hvsm[7],hvso[7];
/*
 * 用int表示扑克牌的方法，假设n为用int表示的扑克牌
 * 花色：n/13，Spades：0，Hearts：1，Diamonds：2，Clubs：3
 * 点数：(n%13)+2，A这里看做12，有时要特判。
 */

inline int StraightF()
{
	//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.
	int s1=-1,s2=-1;
	for(int i=0;i<4;i++)
	{
		if(hvsm[i]>=5)
			s1=i;
		if(hvso[i]>=5)
			s2=i;
	}
	if(s1==-1&&s2==-1)
		return 0;
	int num1=-1,num2=-1;
	for(int i=12;i>=4;i--)
		if(hvm[13*s1+i]&&hvm[13*s1+i-1]&&hvm[13*s1+i-2]&&hvm[13*s1+i-3]&&hvm[13*s1+i-4])
		{
			num1=i;
			break;
		}
	for(int i=12;i>=4;i--)
		if(hvo[13*s2+i]&&hvo[13*s2+i-1]&&hvo[13*s2+i-2]&&hvo[13*s2+i-3]&&hvo[13*s2+i-4])
		{
			num2=i;
			break;
		}
	if(hvm[13*s1+3]&&hvm[13*s1+2]&&hvm[13*s1+1]&&hvm[13*s1+0]&&hvm[13*s1+12]&&num1==-1)
		num1=3;
	if(hvo[13*s2+3]&&hvo[13*s2+2]&&hvo[13*s2+1]&&hvo[13*s2+0]&&hvo[13*s2+12]&&num2==-1)
		num2=3;
	if(num1==-1&&num2==-1)
		return 0;
	if(num1==-1)return -1;
	if(num2==-1)return 1;
	if(num2>=num1)
		return -1;
	else
		return 1;
}

inline int FourOAK()
{
	//Four of a kind: Four cards of the same rank.
	int num11=-1,num12=-1,num21=-1,num22=-1;
	for(int i=12;i>=0;i--)
	{
		if(hvnm[i]>=4&&num11==-1)
			num11=i;
		else if(hvnm[i]>=1&&num12==-1)
			num12=i;
	}
	for(int i=12;i>=0;i--)
	{
		if(hvno[i]>=4&&num21==-1)
			num21=i;
		else if(hvno[i]>=1&&num22==-1)
			num22=i;
	}
	if((num11==-1||num12==-1)&&(num21==-1||num22==-1))return 0;
	if(num11==-1||num12==-1)return -1;
	if(num21==-1||num22==-1)return 1;
	if(num21>num11||(num21==num11&&num22>=num12))
		return -1;
	else
		return 1;
}

inline int FullH()
{
	//Full house: Three cards of the same rank, plus a pair of another rank.
	int num11=-1,num12=-1,num21=-1,num22=-1;
	for(int i=12;i>=0;i--)
	{
		if(hvnm[i]>=3&&num11==-1)
			num11=i;
		else if(hvnm[i]>=2&&num12==-1)
			num12=i;
	}
	for(int i=12;i>=0;i--)
	{
		if(hvno[i]>=3&&num21==-1)
			num21=i;
		else if(hvno[i]>=2&&num22==-1)
			num22=i;
	}
	if((num11==-1||num12==-1)&&(num21==-1||num22==-1))return 0;
	if(num11==-1||num12==-1)return -1;
	if(num21==-1||num22==-1)return 1;
	if(num21>num11||(num21==num11&&num22>=num12))
		return -1;
	else
		return 1;
}

inline int Flush()
{
	//Flush: Five cards of the same suit, but not in sequence.
	int s1=-1,s2=-1;
	for(int i=0;i<4;i++)
	{
		if(hvsm[i]>=5)
			s1=i;
		if(hvso[i]>=5)
			s2=i;
	}
	if(s1==-1&&s2==-1)
		return 0;
	if(s1==-1)
		return -1;
	if(s2==-1)
		return 1;
	int c1=0,c2=0,p1[10],p2[10];
	for(int i=12;i>=0;i--)
		if(hvm[13*s1+i])
		{
			p1[c1++]=i;
			if(c1==5)break;
		}
	for(int i=12;i>=0;i--)
		if(hvo[13*s2+i])
		{
			p2[c2++]=i;
			if(c2==5)break;
		}
	for(int i=0;i<5;i++)
	{
		if(p2[i]>p1[i])
			return -1;
		if(p1[i]>p2[i])
			return 1;
	}
	return -1;
}

inline int Straight()
{
	int num1=-1,num2=-1;
	for(int i=12;i>=4;i--)
		if(hvnm[i]&&hvnm[i-1]&&hvnm[i-2]&&hvnm[i-3]&&hvnm[i-4])
		{
			num1=i;
			break;
		}
	for(int i=12;i>=4;i--)
		if(hvno[i]&&hvno[i-1]&&hvno[i-2]&&hvno[i-3]&&hvno[i-4])
		{
			num2=i;
			break;
		}
	if(hvnm[3]&&hvnm[2]&&hvnm[1]&&hvnm[0]&&hvnm[12]&&num1==-1)
		num1=3;
	if(hvno[3]&&hvno[2]&&hvno[1]&&hvno[0]&&hvno[12]&&num2==-1)
		num2=3;
	if(num1==-1&&num2==-1)
		return 0;
	if(num1==-1)return -1;
	if(num2==-1)return 1;
	if(num2>=num1)
		return -1;
	else
		return 1;
}

inline int ThreeOAK()
{
	//Three of a kind: Just three cards of the same rank.
	int num11=-1,num12=-1,num13=-1,num21=-1,num22=-1,num23=-1;
	for(int i=12;i>=0;i--)
	{
		if(hvnm[i]>=3&&num11==-1)
			num11=i;
		else if(hvnm[i]>=1&&num12==-1)
			num12=i;
		else if(hvnm[i]>=1&&num13==-1)
			num13=i;
	}
	for(int i=12;i>=0;i--)
	{
		if(hvno[i]>=3&&num21==-1)
			num21=i;
		else if(hvno[i]>=1&&num22==-1)
			num22=i;
		else if(hvno[i]>=1&&num23==-1)
			num23=i;
	}
	if((num11==-1||num12==-1||num13==-1)&&(num21==-1||num22==-1||num23==-1))return 0;
	if(num11==-1||num12==-1||num13==-1)return -1;
	if(num21==-1||num22==-1||num23==-1)return 1;
	if(num21>num11||(num21==num11&&num22>num12)||(num21==num11&&num22==num12&&num23>=num13))
		return -1;
	else
		return 1;
}

inline int TwoP()
{
	//Two pairs: Two cards of the same rank, and two other cards of another same rank.
	int num11=-1,num12=-1,num13=-1,num21=-1,num22=-1,num23=-1;
	for(int i=12;i>=0;i--)
	{
		if(hvnm[i]>=2&&num11==-1)
			num11=i;
		else if(hvnm[i]>=2&&num12==-1)
			num12=i;
		else if(hvnm[i]>=1&&num13==-1)
			num13=i;
	}
	for(int i=12;i>=0;i--)
	{
		if(hvno[i]>=2&&num21==-1)
			num21=i;
		else if(hvno[i]>=2&&num22==-1)
			num22=i;
		else if(hvno[i]>=1&&num23==-1)
			num23=i;
	}
	if((num11==-1||num12==-1||num13==-1)&&(num21==-1||num22==-1||num23==-1))return 0;
	if(num11==-1||num12==-1||num13==-1)return -1;
	if(num21==-1||num22==-1||num23==-1)return 1;
	if(num21>num11||(num21==num11&&num22>num12)||(num21==num11&&num22==num12&&num23>=num13))
		return -1;
	else
		return 1;
}

inline int OneP()
{
	//One pair: One pair: Just a pair of cards (two cards) of the same rank.
	int num11=-1,num12=-1,num13=-1,num14=-1,num21=-1,num22=-1,num23=-1,num24=-1;
	for(int i=12;i>=0;i--)
	{
		if(hvnm[i]>=2&&num11==-1)
			num11=i;
		else if(hvnm[i]>=1&&num12==-1)
			num12=i;
		else if(hvnm[i]>=1&&num13==-1)
			num13=i;
		else if(hvnm[i]>=1&&num14==-1)
			num14=i;
	}
	for(int i=12;i>=0;i--)
	{
		if(hvno[i]>=2&&num21==-1)
			num21=i;
		else if(hvno[i]>=1&&num22==-1)
			num22=i;
		else if(hvno[i]>=1&&num23==-1)
			num23=i;
		else if(hvno[i]>=1&&num24==-1)
			num24=i;
	}
	if((num11==-1||num12==-1||num13==-1||num14==-1)&&(num21==-1||num22==-1||num23==-1||num24==-1))return 0;
	if(num11==-1||num12==-1||num13==-1||num14==-1)return -1;
	if(num21==-1||num22==-1||num23==-1||num24==-1)return 1;
	if(num21>num11||(num21==num11&&num22>num12)||(num21==num11&&num22==num12&&num23>num13)||(num21==num11&&num22==num12&&num23==num13&&num24>=num14))
		return -1;
	else
		return 1;
}

inline int Highc()
{
	//High card: Any other hand.
	int num11=-1,num12=-1,num13=-1,num14=-1,num15=-1,num21=-1,num22=-1,num23=-1,num24=-1,num25=-1;
	for(int i=12;i>=0;i--)
	{
		if(hvnm[i]>=1&&num11==-1)
			num11=i;
		else if(hvnm[i]>=1&&num12==-1)
			num12=i;
		else if(hvnm[i]>=1&&num13==-1)
			num13=i;
		else if(hvnm[i]>=1&&num14==-1)
			num14=i;
		else if(hvnm[i]>=1&&num15==-1)
			num15=i;
	}
	for(int i=12;i>=0;i--)
	{
		if(hvno[i]>=1&&num21==-1)
			num21=i;
		else if(hvno[i]>=1&&num22==-1)
			num22=i;
		else if(hvno[i]>=1&&num23==-1)
			num23=i;
		else if(hvno[i]>=1&&num24==-1)
			num24=i;
		else if(hvno[i]>=1&&num25==-1)
			num25=i;
	}
	if((num11==-1||num12==-1||num13==-1||num14==-1||num15==-1)&&(num21==-1||num22==-1||num23==-1||num24==-1||num25==-1))return 0;
	if(num11==-1||num12==-1||num13==-1||num14==-1||num15==-1)return -1;
	if(num21==-1||num22==-1||num23==-1||num24==-1||num25==-1)return 1;
	if(num21>num11||(num21==num11&&num22>num12)||(num21==num11&&num22==num12&&num23>num13)||(num21==num11&&num22==num12&&num23==num13&&num24>num14)||(num21==num11&&num22==num12&&num23==num13&&num24==num14&&num25>=num15))
		return -1;
	else
		return 1;
}

inline int s2n(char c1,char c2)
{
	int num=0;
	//S,H,D,C
	if(c1=='S')
		num=0;
	else if(c1=='H')
		num=13;
	else if(c1=='D')
		num=26;
	else if(c1=='C')
		num=39;
	//A,K,Q,J,T,9,8,7,6,5,4,3,2
	if(c2=='A')
		num+=12;
	else if(c2=='K')
		num+=11;
	else if(c2=='Q')
		num+=10;
	else if(c2=='J')
		num+=9;
	else if(c2=='T')
		num+=8;
	else
		num+=c2-'2';
	return num;
}

inline bool solve()
{
	FILL0(hvm);
	FILL0(hvnm);
	FILL0(hvsm);
	FILL0(hvo);
	FILL0(hvno);
	FILL0(hvso);
	char c1,c2;
	scanf(" %c",&c1);
	if(c1=='#')return 0;
	scanf(" %c",&c2);
	mc1=s2n(c1,c2);
	scanf(" %c%c",&c1,&c2);
	mc2=s2n(c1,c2);
	scanf(" %c%c",&c1,&c2);
	oc1=s2n(c1,c2);
	scanf(" %c%c",&c1,&c2);
	oc2=s2n(c1,c2);
	scanf(" %c%c",&c1,&c2);
	sc1=s2n(c1,c2);
	scanf(" %c%c",&c1,&c2);
	sc2=s2n(c1,c2);
	scanf(" %c%c",&c1,&c2);
	sc3=s2n(c1,c2);
	hvm[mc1]++;
	hvm[mc2]++;
	hvm[sc1]++;
	hvm[sc2]++;
	hvm[sc3]++;
	hvnm[mc1%13]++;
	hvnm[mc2%13]++;
	hvnm[sc1%13]++;
	hvnm[sc2%13]++;
	hvnm[sc3%13]++;
	hvsm[mc1/13]++;
	hvsm[mc2/13]++;
	hvsm[sc1/13]++;
	hvsm[sc2/13]++;
	hvsm[sc3/13]++;
	hvo[oc1]++;
	hvo[oc2]++;
	hvo[sc1]++;
	hvo[sc2]++;
	hvo[sc3]++;
	hvno[oc1%13]++;
	hvno[oc2%13]++;
	hvno[sc1%13]++;
	hvno[sc2%13]++;
	hvno[sc3%13]++;
	hvso[oc1/13]++;
	hvso[oc2/13]++;
	hvso[sc1/13]++;
	hvso[sc2/13]++;
	hvso[sc3/13]++;
	int cnt1=0,cnt2=0;
	for(sc4=0;sc4<52;sc4++)if(!hvo[sc4]&&!hvm[sc4])
	{
		hvm[sc4]++;
		hvnm[sc4%13]++;
		hvsm[sc4/13]++;
		hvo[sc4]++;
		hvno[sc4%13]++;
		hvso[sc4/13]++;
		for(sc5=0;sc5<52;sc5++)if(!hvo[sc5]&&!hvm[sc5])
		{
			hvm[sc5]++;
			hvnm[sc5%13]++;
			hvsm[sc5/13]++;
			hvo[sc5]++;
			hvno[sc5%13]++;
			hvso[sc5/13]++;
			cnt1++;
			int xx=StraightF();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=FourOAK();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=FullH();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=Flush();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=Straight();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=ThreeOAK();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=TwoP();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=OneP();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
			xx=Highc();
			if(xx)
			{
				if(xx==1)cnt2++;
				hvm[sc5]--;
				hvnm[sc5%13]--;
				hvsm[sc5/13]--;
				hvo[sc5]--;
				hvno[sc5%13]--;
				hvso[sc5/13]--;
				continue;
			}
		}
		hvm[sc4]--;
		hvnm[sc4%13]--;
		hvsm[sc4/13]--;
		hvo[sc4]--;
		hvno[sc4%13]--;
		hvso[sc4/13]--;
	}
	printf("%.20lf\n",(double)1.00*cnt2/cnt1);
	return 1;
}

int main()
{
	while(solve());
	return 0;
}