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>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, vector<int> > data;

string A[2],B[2],C[3];

P x[5],y[5],z[5];

void Sort(vector<int> &v){
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
}

void add(vector<int> &v,vector<int> &w){
  for(int i=0;i<(int)w.size();i++)
    v.push_back(w[i]);
}

data calc(vector<P> t){
  data res=data( -1 , vector<int> () );
  
  int st=-1,c3=0,c2=0;
  int s[4]={},maxms=0;
  int f[15]={},maxmf=0;
  for(int i=0;i<5;i++){
    s[ t[i].first ]++;
    if(t[i].second==1)t[i].second=14;
    f[ t[i].second ]++;
  }
  
  for(int i=0;i<4;i++)maxms=max(maxms,s[i]);
  for(int i=2;i<=14;i++){
    maxmf=max(maxmf,f[i]);
    if(f[i]==3)c3++;
    if(f[i]==2)c2++;
  }
  
  
  for(int i=2;i<=10;i++)
    if(f[i]&&f[i+1]&&f[i+2]&&f[i+3]&&f[i+4])st=i;
  if(f[14]&&f[2]&&f[3]&&f[4]&&f[5])st=1;
  
  if(maxms==5&& st!=-1){
    res.first=10;
    for(int i=4;i>=0;i--)
      res.second.push_back(st+i);
    return res;
  }
  if( maxmf == 4 ){
    res.first=8;
    vector<int> tmp;
    for(int i=2;i<=14;i++){
      if(f[i]==4){
        for(int j=0;j<4;j++)
          res.second.push_back(i);
      }else if(f[i]>0){
        for(int j=0;j<f[i];j++)tmp.push_back(i);
      }
    }
    Sort(tmp);
    add(res.second,tmp);
    return res;
  }
  
  if(c3==1&&c2==1){
    res.first=7;
    vector<int> tmp;
    
    for(int i=2;i<=14;i++){
      if(f[i]==3){
        for(int j=0;j<3;j++)res.second.push_back(i);
      }else if(f[i]==2){
        for(int j=0;j<2;j++)tmp.push_back(i);
      }
    }
    add(res.second,tmp);
    return res;
  }

  if(maxms==5){
    res.first=6;
    for(int i=2;i<=14;i++)
      if(f[i])res.second.push_back(i);
    Sort(res.second);
    return res;
  }

  if(st!=-1){
    res.first=5;
    for(int i=4;i>=0;i--)
      res.second.push_back(st+i);
    return res;
  }

  if(c3==1){
    res.first=4;
    vector<int> tmp;
    for(int i=2;i<=14;i++){
      if(f[i]==3){
        for(int j=0;j<3;j++)res.second.push_back(i);
      }else if(f[i]){
        tmp.push_back(i);
      }
    }
    Sort(tmp);
    add(res.second,tmp);
    return res;    
  }

  if(c2==2){
    res.first=3;
    vector<int> tmp;
    for(int i=2;i<=14;i++){
      if(f[i]==2){
        for(int j=0;j<2;j++)res.second.push_back(i);
      }else if(f[i]){
        tmp.push_back(i);
      }
    }
    Sort(res.second);
    Sort(tmp);
    add(res.second,tmp);
    return res;
  }

  if(c2==1){
    res.first=2;
    vector<int> tmp;
    for(int i=2;i<=14;i++){
      if(f[i]==2){
        for(int j=0;j<2;j++)res.second.push_back(i);
      }else if(f[i]){
        tmp.push_back(i);
      }
    }
    Sort(res.second);
    Sort(tmp);
    add(res.second,tmp);
    return res;
  }

  res.first=1;
  for(int i=2;i<=14;i++)
    if(f[i])res.second.push_back(i);
  Sort(res.second);
  return res;
}

data get(vector<P> t){
  data res=data(-1, vector<int>() );

  for(int i=0;i<7;i++){
    for(int j=0;j<i;j++){
      vector<P> tmp;
      
      for(int k=0;k<7;k++)
        if(i!=k&&j!=k)
          tmp.push_back(t[k]);

      res=max(res, calc(tmp));
    }
  }
  return res;
}

bool check(){
  vector<P> vx,vy;
  for(int i=0;i<5;i++){
    vx.push_back(z[i]);
    vy.push_back(z[i]);
    if(i<2){
      vx.push_back(x[i]);
      vy.push_back(y[i]);
    }
  }

  data dx=get(vx);
  data dy=get(vy);

  assert( dx.second.size() == 5 );
  assert( dy.second.size() == 5 );
  if(dx<dy){
    /*
    cout<<z[3].first<<' '<<z[3].second<<endl;
    cout<<z[4].first<<' '<<z[4].second<<endl;
    
    cout<<dx.first<<endl;
    for(int i=0;i<5;i++){
      cout<<dx.second[i]<<' ';
    }
    cout<<endl;
    
    cout<<dy.first<<endl;
    for(int i=0;i<5;i++){
      cout<<dy.second[i]<<' ';
    }
    cout<<endl;
    cout<<endl;
    */
  }
  return (dx>dy);
}


P change(string s){
  P res;
  if(s[0]=='S')res.first=0;
  if(s[0]=='H')res.first=1;
  if(s[0]=='C')res.first=2;
  if(s[0]=='D')res.first=3;
  if(s[1]=='A')res.second=1;
  if(s[1]=='T')res.second=10;
  if(s[1]=='J')res.second=11;
  if(s[1]=='Q')res.second=12;
  if(s[1]=='K')res.second=13;
  if('0'<=s[1]&&s[1]<='9')res.second=s[1]-'0';
  return res;
}

int main(){
  while(1){
    cin>>A[0];
    if(A[0]=="#")break;
    cin>>A[1]>>B[0]>>B[1]>>C[0]>>C[1]>>C[2];
    x[0]=change(A[0]);
    x[1]=change(A[1]);
    y[0]=change(B[0]);
    y[1]=change(B[1]);
    z[0]=change(C[0]);
    z[1]=change(C[1]);
    z[2]=change(C[2]);

    map<P, map<P,bool> > mp;
      
    int count=0;
    int total=0;
    for(int i=0;i<4;i++){
      for(int j=1;j<=13;j++){
        for(int k=0;k<4;k++){
          for(int l=1;l<=13;l++){
            P na=P(i,j);
            P nb=P(k,l);


            if(na==nb)continue;
            bool flg=false;
            for(int m=0;m<3;m++){
              if(m<2&&na==x[m])flg=true;
              if(m<2&&na==y[m])flg=true;
              if(na==z[m])flg=true;
              if(m<2&&nb==x[m])flg=true;
              if(m<2&&nb==y[m])flg=true;
              if(nb==z[m])flg=true;
            }
            if(flg)continue;
            if(mp[na][nb])continue;
            mp[na][nb]=true;
            mp[nb][na]=true;
            total++;
            z[3]=na;
            z[4]=nb;
            
            //            cout<<x[0].first<<' '<<x[0].second<<' ';
            //            cout<<i<<' '<<j<<' '<<k<<' '<<l<<endl;
              
            if(check())count++;

          }
        }
      }
    }

    printf("%.16f\n",(double)(count)/(double)(total));
  }
  return 0;
}