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;
struct card{int num[7],s[7];};

bool flush(const card &c){
  for(int i=0;i<5;i++) if(c.s[0] != c.s[i]) return 0;
  return 1;
}

bool straight(const card &c){
  if(c.num[4] == 13 && c.num[0] == 1) {
    for(int i=0;i<4;i++) if(c.num[i]!=i+1) return 0;
    return 1;
  }
  
  for(int i=0;i<5;i++) if(c.num[i]!=c.num[0]+i) return 0;
  return 1; 
}

bool royal_straight_flush(const card &c){
  for(int i=0;i<5;i++)if(c.num[i] != 9 + i) return 0; 
  return flush(c);
}

bool straight_flush(const card &c){return straight(c)&&flush(c);}
bool four_cards(const card &c){return c.num[0] == c.num[3] || c.num[1] == c.num[4];}
    
bool full_house(const card &c){
  return 
    (c.num[0]==c.num[1] && c.num[2] == c.num[4]) ||
    (c.num[0] == c.num[2] && c.num[3]==c.num[4]);
}

bool three_cards(const card &c){
  for(int i=0;i<3;i++) if(c.num[i] == c.num[i+2]) return 1;
  return 0;
}

bool two_pairs(const card &c){
  int cnt = 0;
  for(int i=0;i<4;i++) if(c.num[i] == c.num[i+1]) cnt++,i++;
  return cnt==2;
}

bool one_pair(const card &c){
  for(int i=0;i<4;i++) if(c.num[i] == c.num[i+1]) return 1;
  return 0;
}

int calcScore(const card &c){
  if(royal_straight_flush(c)) return 0;
  if(straight_flush(c)) return 1;
  if(four_cards(c)) return 2;
  if(full_house(c)) return 3;
  if(flush(c)) return 4;
  if(straight(c)) return 5;
  if(three_cards(c)) return 6;
  if(two_pairs(c)) return 7;
  if(one_pair(c)) return 8;
  return 9;
}

int cmp_all_card(const card &A,const card &B){
  for(int i=4;i>=0;i--)
    if(A.num[i]!=B.num[i]) return A.num[i]<B.num[i]? -1:1;
  return 0;
}

int cmp_four_card(const card &A,const card &B){
  int A4,A1,B4,B1;
  if(A.num[0]==A.num[3]) A4 = A.num[0], A1 = A.num[4];
  else A4 = A.num[4],A1 = A.num[0];
  
  if(B.num[0]==B.num[3]) B4 = B.num[0], B1 = B.num[4];
  else B4 = B.num[4],B1 = B.num[0];

  if(A4!=B4) return A4<B4? -1:1;
  if(A1!=B1) return A1<B1? -1:1;
  return 0;
}

int cmp_full_house(const card &A,const card &B){
  int A3,A2,B3,B2;
  if(A.num[0] == A.num[2]) A3 = A.num[0], A2 = A.num[4];
  else A3 = A.num[4], A2 = A.num[0];

  if(B.num[0] == B.num[2]) B3 = B.num[0], B2 = B.num[4];
  else B3 = B.num[4], B2 = B.num[0];

  if(A3!=B3) return A3<B3? -1:1;
  if(A2!=B2) return A2<B2? -1:1;
  return 0;
}

int cmp_three_card(const card &A,const card &B){
  int A3,B3;
  vector<int> A1,B1;
  for(int i=0;i<5;i++){
    if(i+2<5 && A.num[i] == A.num[i+2]) A3=A.num[i],i+=2;
    else A1.push_back(A.num[i]);
  }

  for(int i=0;i<5;i++){
    if(i+2<5 && B.num[i] == B.num[i+2]) B3=B.num[i],i+=2;
    else B1.push_back(B.num[i]);
  }
  
  if(A3!=B3) return A3<B3? -1:1;
  if(A1[1]!=B1[1]) return A1[1]<B1[1]? -1:1;
  if(A1[0]!=B1[0]) return A1[0]<B1[0]? -1:1;
  return 0;
}


int cmp_two_pairs(const card &A,const card &B){
  int A1,B1;
  vector<int> A2,B2;
  for(int i=0;i<5;i++){
    if(i+1<5 && A.num[i] == A.num[i+1]) A2.push_back(A.num[i]),i++;
    else A1=A.num[i];
  }
  for(int i=0;i<5;i++){
    if(i+1<5 && B.num[i] == B.num[i+1]) B2.push_back(B.num[i]),i++;
    else B1=B.num[i];
  }

  if(A2[1]!=B2[1]) return A2[1]<B2[1]? -1:1;
  if(A2[0]!=B2[0]) return A2[0]<B2[0]? -1:1;
  if(A1!=B1) return A1<B1? -1:1;
  return 0;
}

int cmp_one_pair(const card &A,const card &B){
  vector<int> A1,B1;
  int A2,B2;
  for(int i=0;i<5;i++)
    if(i+1<5 && A.num[i] == A.num[i+1]) A2=A.num[i],i++;
    else A1.push_back(A.num[i]);

  for(int i=0;i<5;i++)
    if(i+1<5 && B.num[i] == B.num[i+1]) B2=B.num[i],i++;
    else B1.push_back(B.num[i]);

  if(A2!=B2) return A2<B2? -1:1;
  if(A1[2]!=B1[2]) return A1[2]<B1[2]? -1:1;
  if(A1[1]!=B1[1]) return A1[1]<B1[1]? -1:1;
  if(A1[0]!=B1[0]) return A1[0]<B1[0]? -1:1;
  return 0;
}

int cmp_straight(const card &A,const card &B){
  if(A.num[0] == 9 && B.num[0] != 9) return 1; 
  if(A.num[0] != 9 && B.num[0] == 9) return -1; 
  if(A.num[0] == 9 && B.num[0] == 9) return 0; 
  if(A.num[4] == 13 && B.num[4] != 13) return -1;
  if(A.num[4] != 13 && B.num[4] == 13) return 1;
  if(A.num[4] == 13 && B.num[4] == 13) return 0;
  return cmp_all_card(A,B);
}

//1 -> win, 0 -> draw, -1 -> lose
int compare(const card A,const card B){
  int scoreA = calcScore(A);
  int scoreB = calcScore(B);
  if(scoreA!=scoreB) return -scoreA<-scoreB? -1:1;
  if(scoreA == 0) return 0; //royal
  if(scoreA == 1) return cmp_straight(A,B); //straight flush
  if(scoreA == 2) return cmp_four_card(A,B); // four
  if(scoreA == 3) return cmp_full_house(A,B); // full house
  if(scoreA == 4) return cmp_all_card(A,B); // flush
  if(scoreA == 5) return cmp_straight(A,B); // straight
  if(scoreA == 6) return cmp_three_card(A,B); // three
  if(scoreA == 7) return cmp_two_pairs(A,B); // two
  if(scoreA == 8) return cmp_one_pair(A,B); // one
  return cmp_all_card(A,B); // no
}

int getNum(char ch){
  if(isdigit(ch)) return ch - '1';
  if(ch == 'A') return 13;
  if(ch == 'K') return 12;
  if(ch == 'Q') return 11;
  if(ch == 'J') return 10;
  if(ch == 'T') return 9;
}

int getSuit(char ch){
  if(ch == 'S') return 0;
  if(ch == 'H') return 1;
  if(ch == 'D') return 2;
  if(ch == 'C') return 3;
}

card choice(card A){
  card res;res.num[0] = -1;
  
  for(int i=0;i<7;i++)
    for(int j=0;j<7;j++){
      if(i==j)continue;
      card B;
      for(int k=0,idx=0;k<7;k++) 
        if(i!=k && j!=k) B.num[idx] = A.num[k], B.s[idx]=A.s[k],idx++;
      sort(B.num,B.num+5);
      if(res.num[0] == -1 || compare(B,res) == 1) res = B;
    }
  return res;
}

int game(const card &A,const card &B){return compare(choice(A),choice(B))==1;}

int used[4][14];
int cnt,win;
void choice(int idx,card &A,card &B){
  if(idx == 7)win += game(A,B), cnt++;
  if(idx == 7)return;
  
  for(int i=0;i<4;i++)
    for(int j = 1;j<14;j++) {
      if(used[i][j])continue;
      used[i][j] = 1;
      A.s[idx] = B.s[idx] = i;
      A.num[idx] = B.num[idx] = j;
      choice(idx+1,A,B);
      used[i][j] = 0;
    }
}

int main(){
  while(1){
    memset(used,0,sizeof(used));
    card A,B;
    for(int i=0;i<2;i++){
      char suit,num;
      cin>>suit;
      if(suit == '#')exit(0);
      cin>>num;
      A.s[i] = getSuit(suit);
      A.num[i] = getNum(num);
      used[A.s[i]][A.num[i]] = 1;
    }

    for(int i=0;i<2;i++){
      char suit,num;
      cin>>suit>>num;
      B.s[i] = getSuit(suit);
      B.num[i] = getNum(num);
      used[B.s[i]][B.num[i]] = 1;
    }

    for(int i=0;i<3;i++){
      char suit,num;
      cin>>suit>>num;
      A.s[i+2] = B.s[i+2] = getSuit(suit);
      A.num[i+2] = B.num[i+2] = getNum(num);
      used[A.s[i+2]][A.num[i+2]] = 1;
    }

    cnt = win = 0;
    choice(5,A,B);
    printf("%.10lf\n",(double)win/cnt);
  }
  return 0;
}