#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE

signed main(){
  string yc1,yc2,oc1,oc2,cc1,cc2,cc3;
  while(cin>>yc1,yc1!="#"s){
    cin>>yc2;
    cin>>oc1>>oc2;
    cin>>cc1>>cc2>>cc3;

    auto idx=
      [&](string s){
        int res=0;
        if(s[0]=='S') res=0;
        if(s[0]=='H') res=1;
        if(s[0]=='D') res=2;
        if(s[0]=='C') res=3;
        res*=13;
        if(isdigit(s[1])) res+=s[1]-'1';
        if(s[1]=='A') res+=0;
        if(s[1]=='T') res+=9;
        if(s[1]=='J') res+=10;
        if(s[1]=='Q') res+=11;
        if(s[1]=='K') res+=12;        
        return res;
      };
    vector<int> used(52,0);
    used[idx(yc1)]=1;
    used[idx(yc2)]=1;
    used[idx(oc1)]=1;
    used[idx(oc2)]=1;
    used[idx(cc1)]=1;
    used[idx(cc2)]=1;
    used[idx(cc3)]=1;

    vector<int> rsf({0,9,10,11,12});    
    auto roll=
      [&](const vector<int> &A)->int{
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());
        int flg=1;
        for(int i=0;i<4;i++) flg&=vs[i]+1==vs[i+1];
          
        // Royal straight flush
        if(ss.size()==1u&&vs==rsf) return 1;

        // Straight flush
        if((ss.size()==1u)&&flg) return 2;

        // Four of a kind (4 + 1)
        for(auto p:ms)
          if(p.second==4) return 3;

        // Full house (3 + 2)
        if(ms.size()==2u) return 4;
        
        // Flush
        if(ss.size()==1u) return 5;
        
        // Straight
        if((vs==rsf)||flg) return 6;

        // Three of a kind (3 + 1 + 1)
        for(auto p:ms)
          if(p.second==3) return 7;
        
        // Two pairs (2 + 2 + 1)
        if(ms.size()==3u) return 8;

        // One pair (2 + 1 + 1 + 1)
        if(ms.size()==4u) return 9;

        // High card
        return 10;
      };
    
    auto stra=
      [&](const vector<int> &A){
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());
        if(vs==rsf) return 13;
        return *vs.rbegin();
      };
    
    auto four=
      [&](const vector<int> &A){
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());

        int x=-1,y=-1;
        for(auto p:ms)
          if(p.second==4) x=p.first;
          else y=p.first;
        if(x==0) x=13;
        if(y==0) y=13;
        return make_tuple(x,y);
      };
    
    auto full=
      [&](const vector<int> &A){
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());

        int x=-1,y=-1;
        for(auto p:ms)
          if(p.second==3) x=p.first;
          else y=p.first;
        if(x==0) x=13;
        if(y==0) y=13;
        return make_tuple(x,y);
      };
    
    auto high=
      [&](const vector<int> &A){
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());
        if(vs[0]==0) vs[0]=13;
        sort(vs.rbegin(),vs.rend());
        return make_tuple(vs[0],vs[1],vs[2],vs[3],vs[4]);
      };

    
    auto trip=
      [&](const vector<int> &A){
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());
        
        int x=-1,y=-1,z=-1;
        for(auto p:ms)
          if(p.second==3) x=p.first;
          else if(y<0) y=p.first;
          else z=p.first;
        
        if(x==0) x=13;
        if(y==0) y=13;
        if(z==0) z=13;
        if(y<z) swap(y,z);
        return make_tuple(x,y,z);
      };
    
    
    auto twop=
      [&](const vector<int> &A){
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());
        
        int x=-1,y=-1,z=-1;
        for(auto p:ms)
          if(p.second==2&&x<0) x=p.first;
          else if(p.second==2) y=p.first;
          else z=p.first;
        
        if(x==0) x=13;
        if(y==0) y=13;
        if(z==0) z=13;
        if(x<y) swap(x,y);
        return make_tuple(x,y,z);
      };
    
    auto onep=
      [&](const vector<int> &A){
        set<int> ss;
        map<int, int> ms;
        vector<int> vs(5);
        for(int i=0;i<5;i++){
          ss.emplace(A[i]/13);
          vs[i]=A[i]%13;
          ms[A[i]%13]++;
        }
        sort(vs.begin(),vs.end());
        
        int x=-1;
        vector<int> us;
        for(auto p:ms){
          if(p.second==2) x=p.first;
          else us.emplace_back(p.first?p.first:13);
        }
        
        if(x==0) x=13;
        sort(us.rbegin(),us.rend());
        return make_tuple(x,us[0],us[1],us[2]);
      };
    
    
    auto cmp=
      [&](const vector<int> &A,const vector<int> &B)->int{
        if(A.empty()) return 0;
        if(B.empty()) return 1;
        int x=roll(A),y=roll(B);
        if(x!=y) return x<y;
        if(x==1) return 0;        
        if(x==2) return stra(A)>stra(B);
        if(x==3) return four(A)>four(B);
        if(x==4) return full(A)>full(B);
        if(x==5) return high(A)>high(B);
        if(x==6) return stra(A)>stra(B);
        if(x==7) return trip(A)>trip(B);
        if(x==8) return twop(A)>twop(B);
        if(x==9) return onep(A)>onep(B);
        
        if(x==10) return high(A)>high(B);
        return 0;
      }; 


    vector<int> bs;
    for(int b=0;b<(1<<7);b++){
      if(__builtin_popcount(b)!=5) continue;
      bs.emplace_back(b);
    }
    
    auto calc=
      [&](vector<int> v){
        vector<int> res,u(5);
        for(int b:bs){
          for(int i=0,k=0;i<7;i++)
            if((b>>i)&1) u[k++]=v[i];
          if(cmp(u,res)) res=u;
        }
        return res;
      };

    int y1=idx(yc1),y2=idx(yc2);
    int o1=idx(oc1),o2=idx(oc2);
    int x=idx(cc1),y=idx(cc2),z=idx(cc3);
    
    int win=0,cnt=0;
    for(int i=0;i<52;i++){
      for(int j=0;j<i;j++){
        if(used[i]||used[j]) continue;
        cnt++;
        auto A=calc({y1,y2,x,y,z,i,j});
        auto B=calc({o1,o2,x,y,z,i,j});
        if(cmp(A,B)) win++;
      }
    }
    
    cout<<((double)win)/cnt<<endl;
  }
  return 0;
}



Measured memory_bytes: 3236