#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;
}

Measured memory_bytes: 3060