/*
  AOJ 2535
  Title:Texas hold 'em
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#define max(x,y) (((x)>(y))?(x):(y))
int your_card[2];
int oppo_card[2];
int comm_card[3];
int turn,river;
char suits_str[]="SHCD";
char rank_str[]="A23456789TJQK";
#define ROYAL 10
#define STFL 9
#define FOURCARDS 8
#define FULLHOUSE 7
#define FLASH 6
#define STRAIGHT 5 
#define THREECARDS 4
#define TOWPAIR 3
#define ONEPAIR 2
#define NOPAIR 1

int ncomp[11]={0,5,4,3,3,1,5,2,2,1,0}; // zero base

int comp_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int is_straight(int cards[7],int flag[5],int rank_dist[14],int flash_suit)
{
  int i;

  for(i=13;i>=4;i--)
    if(rank_dist[i] && rank_dist[i-1] && rank_dist[i-2] && 
       rank_dist[i-3] && rank_dist[i-4] )
      {
	flag[0]=i;
	return(-1);
      }
  return(0);
}

int is_royal(int cards[7],int flag[5],int rank_dist[14],int s)
{
  int i,f,r;

  if(s<0)
    return(0);

  for(i=0,f=0;i<7;i++)
    {
      if(cards[i]/13==s)
	{
	  r=cards[i]%13;
	  if(r==0||(r>8 && r < 13))
	    f++;
	}
    }
  return(f==5);
}
int is_stfl(int cards[7],int flag[5],int rank_dist[14],int s)
{
  int i,p;

  if(s<0)
    return(0);
  qsort(cards,7,sizeof(int),comp_int);
  for(i=6;i>3;i--)
    {
      if(cards[i]%13 >= 4 && cards[i]-4==cards[i-4])
	{
	  flag[0]=cards[i]%13;
	  return(1);
	}
    }
  return(0);
}
int is_flash(int cards[7],int flag[5],int rank_dist[14],int s)
{
  int i,p,j,rank;

  if(s<0)
    return(0);
  qsort(cards,7,sizeof(int),comp_int);
  for(i=6,p=0;i>=0;i--)
    {
      if(cards[i]/13==s)
	{
	  rank=cards[i]%13;
	  if(rank==0) //ace no shori
	    {
	      if(p>0)
		for(j=p-1;j>=0;j--)
		  flag[j+1]=flag[j];
	      flag[0]=13;
	      p++;
	    }
	  else
	    flag[p++]=rank;
	}
    }


  return(1);
}
int is_fourcards(int cards[7],int flag[5],int rank_dist[14],int flash_suit)
{
  int i,npair,p;
  p=npair=0;
  for(i=13;i>=1;i--)
    if(rank_dist[i]==4)
      {
	npair++;
	flag[0]=i;
      }
  if(npair<1)
    return(0);
  npair=0;
  for(i=13;i>=0;i--)
    if(rank_dist[i]>0 && rank_dist[i]<4)
      {
	flag[1]=i;
	break;
      }
    return(1);
}
int is_fullhouse(int cards[7],int flag[5],int rank_dist[14],int flash_suit)
{
  int i,npair,p;
  p=npair=0;
  for(i=13;i>=1;i--)
    if(rank_dist[i]==3)
      {
	npair++;
	flag[0]=i;
	break;
      }
  if(npair<1)
    return(0);

  npair=0;
  for(i=13;i>=1;i--)
    if(rank_dist[i]>=2 && i!=flag[0])
      {
	npair++;
	flag[1]=i;
	break;
      }
  if(npair<1)
    return(0);
  else
    return(1);
}
int is_threecards(int cards[7],int flag[5],int rank_dist[14],int flash_suit)
{
  int i,npair;
  npair=0;
  for(i=13;i>=1;i--)
    if(rank_dist[i]==3)
      {
	npair++;
	flag[0]=i;
      }
  if(npair<1)
    return(0);
  for(i=13;i>=1;i--)
    if(rank_dist[i]==1)
      {
	flag[1]=i;
	break;
      }
  for(i=13;i>=1;i--)
    if(rank_dist[i]==1 && i<flag[1])
      {
	flag[2]=i;
	break;
      }
  return(1);
}
int is_twopairs(int cards[7],int flag[5],int rank_dist[14],int flash_suit)
{
  int i,npair,p;
  p=npair=0;
  for(i=13;i>=1;i--)
    if(rank_dist[i]==2)
      {
	npair++;
	flag[p]=i;
	p++;
      }
  if(npair<2)
    return(0);
  for(i=13;i>=1;i--)
    if(rank_dist[i]>=1 && i!=flag[0] && i!=flag[1])
      {
	flag[2]=i;
	break;
      }
  return(1);
}
int is_nopair(int cards[7],int flag[5],int rank_dist[14],int flash_suit)
{
  int i,p;
  for(i=13,p=0;i>=1;i--)
    {
      if(rank_dist[i]>=2)
	return(0);
      if(rank_dist[i]==1)
	{
	  flag[p]=i;
	  p++;
	  if(p>4)
	    break;
	}
    }
  return(1);
}
int is_onepair(int cards[7],int flag[5],int rank_dist[14],int flash_suit)
{
  int i,npair,p;
  for(i=13,npair=0;i>=1;i--)
    if(rank_dist[i]==2)
      {
	//printf("pair=%d\n",i);
	npair++;
	flag[0]=i;
      }
  //printf("npair=%d\n",npair);
  if(npair!=1)
    return(0);
  for(i=13,p=1;i>=1;i--)
    if(rank_dist[i]==1)
      {
	flag[p]=i;
	p++;
      }
  return(1);
}

int ((*func[11])(int *,int *,int *,int))=
{NULL,is_nopair,is_onepair,is_twopairs,
 is_threecards,is_straight,is_flash,
 is_fullhouse,is_fourcards,is_stfl,is_royal};

void dump(int suit_dist[],int rank_dist[])
{
  int i;
  for(i=0;i<4;i++)
    printf("%d:",suit_dist[i]);
  printf("\n");
  for(i=0;i<13;i++)
    printf("%d:",rank_dist[i]);
  printf("\n");
}

int yaku(int cards[7],int flag[])
{
  int i,fl,ret;
  int rank_dist[14]; //ace occurs twice
  int suit_dist[4];
  int flash_suit;

  for(i=0;i<13;i++)
    rank_dist[i]=0;
  for(i=0;i<4;i++)
    suit_dist[i]=0;
  for(i=0;i<7;i++)
    {
      rank_dist[cards[i]%13]++;
      suit_dist[cards[i]/13]++;
    }
  rank_dist[13]=rank_dist[0];

  for(i=0,flash_suit=-1;i<4;i++)
    {
      if(suit_dist[i]>=5)
	flash_suit=i;
    }
#ifdef DEBUG
  dump(suit_dist,rank_dist);
#endif

  for(i=10;i>=1;i--)
    {
      ret=(*func[i])(cards,flag,rank_dist,flash_suit);
      if(ret)
	return(i);
    }
  return(1);
}
int comp2(int yh[7],int oh[7])
{
  int yf[7],of[7],i;
  int yyaku,oyaku;
  yyaku=yaku(yh,yf);
  oyaku=yaku(oh,of);
  //#ifdef DEBUG

  //printf(";:%d %d\n",yyaku,oyaku);
  //#endif
  if(yyaku>oyaku)
    return(1);
  if(yyaku<oyaku)
    return(0);
    
  for(i=0;i<ncomp[yyaku];i++)
    {
#ifdef DEBUG
      printf("::%d %d\n",yf[i]+1,of[i]+1);
#endif
      if(yf[i]>of[i])  //kicker
	return(1);
      if(yf[i]<of[i])
	return(0);
    }
  return(-1);
}
int compare_hand(int you[2],int oppo[2],int com[3],int turn,int river)
{
  int i;

  int your_hand[7],oppo_hand[7];
  for(i=0;i<2;i++)
      {
	your_hand[i]=you[i];
	oppo_hand[i]=oppo[i];
      }
  for(i=0;i<3;i++)
    your_hand[2+i]=oppo_hand[2+i]=com[i];
  your_hand[5]=oppo_hand[5] = turn;
  your_hand[6]=oppo_hand[6] = river;
  return(comp2(your_hand,oppo_hand));
}
int suit2num(char suit)
{
  return(strchr(suits_str,suit)-suits_str);
}
int rank2num(char rank)
{
  return(strchr(rank_str,rank)-rank_str);
}
int check_duplicate(int c,int your_card[],int oppo_card[],int comm_card[])
{
  int i;
  for(i=0;i<2;i++)
    if(c==your_card[i])
      return(-1);
  for(i=0;i<2;i++)
    if(c==oppo_card[i])
      return(-1);
  for(i=0;i<3;i++)
    if(c==comm_card[i])
      return(-1);
  return(0);
}
int check_duplicate2(int c,int c2,int your_card[],
int oppo_card[],int comm_card[])
{
  if(c==c2)
    return(-1);
  else    
    return(check_duplicate(c2,your_card,oppo_card,comm_card));
}
#ifdef DEBUG


main()
{
  int hand[2][7],flag[5];
  int i,ns,nr,y,j,ret;
  char card[2];
  
  for(j=0;j<2;j++)
    {

      for(i=0;i<7;i++)
	{
	  scanf("%s",card);

	  if(card[0]=='#')
	    goto END;
	  
	  ns=suit2num(card[0]);
	  nr=rank2num(card[1]);
	  hand[j][i]=13*ns+nr;
	}
    }
  ret=comp2(&hand[0][0],&hand[1][0]);
  printf("win=%s\n",(ret>0)?"WIN":((ret==0)?"LOSE":"TIE"));
 END:
  return(0);
}

#else

main()
{
  int i,j,bunbo,bunsi;
  char buf[2],suit,rank;
  
  while(1)
    {
      scanf("%s",&buf[0]); 
      if('#'==buf[0])
	break;

      your_card[0]=13*suit2num(buf[0])+rank2num(buf[1]);
      scanf("%s",&buf[0]);	
      your_card[1]=13*suit2num(buf[0])+rank2num(buf[1]);

      for(i=0;i<2;i++)
	{
	  scanf("%s",&buf[0]);	
	  oppo_card[i]=13*suit2num(buf[0])+rank2num(buf[1]);
	}
      for(i=0;i<3;i++)
	{
	  scanf("%s",&buf[0]);	
	  comm_card[i]=13*suit2num(buf[0])+rank2num(buf[1]);
	}
      bunbo=bunsi=0;
      for(i=0;i<52;i++)
	{
	  if(check_duplicate(i,your_card,oppo_card,comm_card))
	     continue;
	  turn=i;
	  for(j=0;j<52;j++)
	    {
	      if(check_duplicate2(i,j,your_card,oppo_card,comm_card))
		continue;
	      river=j;
	      bunbo++;
	      if(compare_hand(your_card,oppo_card,comm_card,turn,river)>0)
		{
		  bunsi++;
		  //printf("tr=%d %d\n",turn,river);
		}
	    }
	}
      printf("%.7lf\n",((double)bunsi)/((double)bunbo));
    }
  return(0);
}

#endif

Measured memory_bytes: 604