#include <stdio.h>
#include <stdlib.h>
 char a[1],b[3],c[3];
int j(char d)
    {
        if(d=='T') return 10;
      else if(d=='J') return 11;
      else if(d=='Q') return 12;
      else if(d=='K') return 13;
      else if(d=='A') return 14;
      else return d-'0';
    }
int main()
{
   scanf("%s%s%s",c,a,b);
   if(a[1]==b[1])
   {
       if(j(a[0])>j(b[0]))
        printf("YES");
        else printf("NO");
   }
   else if (c[0]==a[1])
   {
       printf("YES");
   }
    else printf("NO");

    return 0;
}

#include <stdio.h>
#include <string.h>

int main()
{
    char *s = "6789TJQKA1", c, a, x, b, y;
    scanf("%c\n%c%c %c%c", &c, &a, &x, &b, &y);
    puts( x == c && y != c || x == y && strchr(s, a) > strchr(s, b) ? "YES" : "NO" );
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int num(char ch){
    if (ch >= '6' && ch <= '9'){
        return ch - '0';
    }
    if (ch == 'J'){
        return 11;
    }
    if (ch == 'T'){
        return 10;
    }
    if (ch == 'K'){
        return 13;
    }
    if (ch == 'Q'){
        return 12;
    }
    return 14;
}

int main(void)
{
    int a1, a2;
    char koz, c1, c2, ch;
    scanf("%c\n", &koz);
    scanf("%c%c", &ch, &c1);
    a1 = num(ch);
    scanf("%c", &ch);
    scanf("%c%c", &ch, &c2);
    a2 = num(ch);
    if ((c1 == c2 && a2 < a1) || (c1 == koz && c2 != koz)){
        printf("YES");
    }else{
        printf("NO");
    }

    return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{char t,p[5],q[3];
scanf("%s",&t);

scanf("%s%s",p,q);
switch(p[0])
{case 'T':p[0]='A';break;
 case 'J':p[0]='B';break;
 case 'Q':p[0]='C';break;
  case 'K':p[0]='D';break;
   case 'A':p[0]='E';break;
 }
 switch(q[0])
{case 'T':q[0]='A';break;
 case 'J':q[0]='B';break;
 case 'Q':q[0]='C';break;
  case 'K':q[0]='D';break;
   case 'A':q[0]='E';break;
 }
if(p[1]==q[1])
{if(p[0]>q[0])
{printf("YES");
return 0;}}
else
if(p[1]==t)
{printf("YES");return 0;}
printf("NO");
return 0;
}

#include <stdio.h>

int dec(char c){
	switch(c){
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	case 'T': return 10;
	case 'J': return 11;
	case 'Q': return 12;
	case 'K': return 13;
	case 'A': return 15;
	}
}

int istrump(char trump,char this){
	if(trump==this)return 1;
	else return 0;
}

int main(void)
{
        char a,b,c,d,e;
        int scorea,scoreb;
        int win;
        scanf(" %c",&a);
        //fflush(stdin);
        scanf(" %c%c %c%c",&b,&c,&d,&e);
        if(istrump(a,c)){
                if(istrump(a,e)){
                        if(dec(b)>=dec(d))win=1;
                        else win=0;
                }
                else win=1;
        }
        else{
                if(c==e){
                        if(dec(b)>=dec(d))win=1;
                        else win=0;
                }
                else if(istrump(a,e)){
                        win=0;
                }
                else win=0;
        }

        if(win)puts("YES");
        else puts("NO");

        return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,c1,c2;
    char mal;
    char bal[]={'6','7','8','9','T','J','Q','K','A'};
    char kang[4],bang[4];
    scanf("%c",&mal);
    scanf("%s %s",kang,bang);
    for (i=0;i<9;i++)
    {
        if (bal[i]==kang[0]) c1=i+1;
        if (bal[i]==bang[0]) c2=i+1;
    }
    if (kang[1]==bang[1])
    {
        if(c1>c2) printf("YES");
        else printf("NO");
    }
    else
    {
        if (kang[1]==mal) printf("YES");
        else printf("NO");
    }
}

main(){
    int i=0,j=0,map[225];
    char c,card1[5],card2[5],s[20]="6789TJQKASHDC";
    while(s[i])    map[s[i++]]=j++;
    scanf("%c %s %s",&c,card1,card2);
    if(card1[1]==card2[1]){
        if(map[card1[0]]>map[card2[0]])    printf("YES\n");
        else    printf("NO\n");
    }
    else if(card1[1]==c)    printf("YES\n");
    else    printf("NO\n");
    return 0;
}

#include <stdio.h>

#define SIM 1
#define NAO 0

int main() {
	char trunfo, valor1, valor2, naipe1, naipe2;
	int vitoria = NAO, num1, num2;

	num1 = num2 = 1;

	scanf (" %c", &trunfo);
	scanf (" %c %c", &valor1, &naipe1);

	switch (valor1) {
		case '6':		break;
		case '7':		num1 = 2; break;
		case '8':		num1 = 3; break;
		case '9':		num1 = 4; break;
		case 'T':		num1 = 5; break;
		case 'J':		num1 = 6; break;
		case 'Q':		num1 = 7; break;
		case 'K':		num1 = 8; break;
		case 'A':		num1 = 9; break;
	}

	scanf (" %c %c", &valor2, &naipe2);

	switch (valor2) {
		case '6':		break;
		case '7':		num2 = 2; break;
		case '8':		num2 = 3; break;
		case '9':		num2 = 4; break;
		case 'T':		num2 = 5; break;
		case 'J':		num2 = 6; break;
		case 'Q':		num2 = 7; break;
		case 'K':		num2 = 8; break;
		case 'A':		num2 = 9; break;
	}

	if (naipe1 == naipe2) {
		if (num1 > num2)
			vitoria = SIM;
	}

	else {
		if (naipe1 == trunfo)
			vitoria = SIM;
	}

	if (vitoria)
		printf ("YES\n");
	else printf ("NO\n");

	return 0;
}

#include <stdio.h>

int func(char c)
{
    if(c=='6' || c=='7' || c=='8' || c=='9')
        return (c-'0');
    else if(c=='T')
        return 10;
    else if(c=='J')
        return (11);
    else if(c=='Q')
        return (12);
    else if(c=='K')
        return 13;
    else if(c=='A')
        return 14;
}

int main()
{
    char trump[2], a[3], b[3];
    scanf("%s", trump);
    scanf("%s", a);
    scanf("%s", b);
    //printf("%c %s %s", trump[0], a, b);
    //printf("%d %d %d %d %d %d %d %d %d\n", '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A');
    if(a[1]!=b[1])
    {
        if(a[1]!=trump[0])
            printf("NO\n");
        else
            printf("YES\n");
    }
    else
    {
        int v1, v2;
        v1=func(a[0]);
        v2=func(b[0]);
        //printf("%d %d\n", v1, v2);
        if(v1>v2)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char index[9]={'6','7','8','9','T','J','Q','K','A'};

int main()
{
 		char trump;
 		char a[3],b[3];
 		scanf("%c",&trump);
 		if(trump!='H'&&trump!='S'&&trump!='D'&&trump!='C')
 		  exit(0);
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
	  scanf("%s%s",a,b);
	  int marka,markb;
	  if(a[1]==trump&& b[1]!=trump)
	  {
	     printf("YES\n");
	     return 0;
    }
    if(a[1]!=trump && b[1]==trump)
    {
		   printf("NO\n");
       return 0;
    }
    else
    {
     		int i=0;
    		for(i=0;i<9;i++)
    		{
						if(a[0]==index[i])
				      marka=i;
       			if(b[0]==index[i])
              markb=i;
				}
				if(a[1]==b[1])
				{
    		   if(marka<markb)
					    printf("NO\n");
           else
              printf("YES\n");
				}
				else
				   printf("NO\n");
	   return 0;
		 }
}

#include <stdio.h>

int main()
{
	char a, b, c, d, e, f, g;
	char ZA[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};

	scanf("%c\n%c%c %c%c", &a, &b, &c, &d, &e);
	if (c != e && c == a)
		printf("YES\n");
	else if (c == e) {
		for (f = 0; f < 10; ++f)
			if (ZA[f] == b)
				break;
		for (g = 0; g < 10; ++g)
			if (ZA[g] == d)
				break;
		if (f > g)
			printf("YES\n");
		else
			printf("NO\n");
	} else
		printf("NO\n");

	return 0;
}

#include <stdio.h>

int value_converter(char temp) {
    if(temp=='6') {
        return 6;
    } else if(temp=='7') {
        return 7;
    } else if(temp=='8') {
        return 8;
    } else if(temp=='9') {
        return 9;
    } else if(temp=='T') {
        return 10;
    } else if(temp=='J') {
        return 11;
    } else if(temp=='Q') {
        return 12;
    } else if(temp=='K') {
        return 13;
    } else if(temp=='A') {
        return 14;
    }
    else if(temp=='S') {
        return 15;
    }
    else if(temp=='H') {
        return 16;
    }
    else if(temp=='D') {
        return 17;
    }
    else if(temp=='C') {
        return 18;
    }

}

int main() {

    char trump, p1, p2 , p3, p4;

    scanf("%c\n", &trump);
    scanf("%c%c %c%c", &p1,&p2,&p3,&p4);

   // printf("%c %c %c %c\n",p1,p2,p3,p4);
    int integer_value_of_p11 = value_converter(p1);
    int integer_value_of_p21 = value_converter(p3);

    if( p2==p4 ){
        if( integer_value_of_p11 > integer_value_of_p21 ){
            printf("YES");
        }
        else{
            printf("NO\n");
        }
    }
    else if(p2==trump) {
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct card{
  char suit;
  char rank;
};

int win(struct card c1,struct card c2,char trump);
int num(char c);

int main(void){
  struct card c[2];
  char trump;
  scanf("%c%*c",&trump);
  scanf("%c%c %c%c%*c",&c[0].rank,&c[0].suit,&c[1].rank,&c[1].suit);
  if(win(c[0],c[1],trump)) puts("YES");
  else puts("NO");
  return 0;
}

int win(struct card c1,struct card c2,char trump){
  if(c1.suit==trump && c2.suit!=trump) return 1;
  if(c2.suit==trump && c1.suit!=trump) return 0;
  if(c1.suit!=c2.suit) return 0;
  if(num(c1.rank)<num(c2.rank)) return 0;
  else return 1;
}

int num(char c){
  switch(c){
  case 'T':
    return 10;
    break;
  case 'J':
    return 11;
    break;
  case 'Q':
    return 12;
    break;
  case 'K':
    return 13;
    break;
  case 'A':
    return 14;
    break;
  default:
    return c-'0';
  }
}

#include<stdio.h>
#include<stdlib.h>

int main(int ac, char** av)
{
    char trump_suit;
    char first[3], second[3];
    int val1, val2;

    scanf(" %c %s %s",&trump_suit, first, second);

    /* printf(" trump_suit = %c, first card= %s and second card = %s", trump_suit, first, second); */

    if(first[1] == trump_suit && second[1] != trump_suit)
        printf("YES\n");
    else if( (first[1] != trump_suit && second[1] == trump_suit) ||
                                first[1] != second[1] )
        printf("NO\n");
    else
    {
        if(first[0]>='2' && first[0]<='9')
            val1 =  first[0]-'0';
        else if(first[0]=='T')
            val1 = 10;
        else if(first[0]=='J')
            val1 = 11;
        else if(first[0]=='Q')
            val1 = 12;
        else if(first[0]=='K')
            val1 = 13;
        else if(first[0]=='A')
            val1 = 14;
        else
            printf("INVALID CARD!");

        if(second[0]>='2' && second[0]<='9')
            val2 =  second[0]-'0';
        else if(second[0]=='T')
            val2 = 10;
        else if(second[0]=='J')
            val2 = 11;
        else if(second[0]=='Q')
            val2 = 12;
        else if(second[0]=='K')
            val2 = 13;
        else if(second[0]=='A')
            val2 = 14;
        else
            printf("INVALID CARD!");

        if(val1 > val2)
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;

}

#include <stdio.h>
#include <string.h>
int max(int a,int b){
	return a>b?a:b;
}
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	char a,b,c,d,e;int k=0;
scanf("%c\n%c%c %c%c",&a,&b,&c,&d,&e);
	if(b=='A')b='Z';
	if(b=='T')b='A';
	if(b=='K')b='Y';
	if(d=='A')d='Z';
	if(d=='T')d='A';
	if(d=='K')d='Y';
	if((a==c)&&(a!=e)) k=1;
	if((c==e)&&(b>d))k=1;

	printf(k?"YES":"NO");
}

/* Author: Abhay
   Problem: 106A Codeforces
   Language: C
   */

#include <stdio.h>

char cards[9] = {'6','7','8','9','T','J','Q','K','A'};

int main ()
{
    int i, index1, index2, ans;
    char trump, card1[3], card2[3];

    scanf ("%c", &trump);
    scanf ("%s %s", &card1, card2);

    ans = 0;

    if (card1[1] == card2[1])
    {
        for (i=0; i<9; i++)
        {
            if (cards[i] == card1[0])
                index1 = i;
            if (cards[i] == card2[0])
                index2 = i;
        }
        if (index1 > index2)
            ans = 1;
    }

    else if (card1[1] == trump)
        ans = 1;

    if (ans)
        printf ("YES\n");
    else
        printf ("NO\n");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

char rank[9]={'6','7','8','9','T','J','Q','K','A'};

int gana(int trump,char first[2],char second[2]);
int indice(char C);
int main()
{
    char trump;
    scanf("%c",&trump);
    getchar();
    char first[2];
    char second[2];
    int i;
    for(i=0;i<2;i++){scanf("%c",&first[i]);}getchar();
    for(i=0;i<2;i++){scanf("%c",&second[i]);}getchar();

    if(gana(trump,first,second)){
        printf("YES");
    } else {
    printf("NO");
    }

    return 0;
}

int indice(char C){
int i=0;
while(rank[i]!=C){i++;}
return i;
}

int gana(int trump,char first[2],char second[2]){

if((first[1]==trump)&&(second[1]!=trump) ) return 1;
if((first[1]!=trump)&&(second[1]==trump) ) return 0;
if((first[1]==second[1]) && (indice(first[0])>indice(second[0]))) return 1;

return 0;
}

#include <stdio.h>

int f(char c) {
    if (c <= 0x39) {
        return c - 0x36;
    }

    switch (c) {
        case ('T'):
            return 4;
        case ('J'):
            return 5;
        case ('Q'):
            return 6;
        case ('K'):
            return 7;
        case ('A'):
            return 8;
    }

    return -1;
}

int main () {
    char c = 0;
    char s1[3] = {0};
    char s2[3] = {0};

    scanf("%c %s %s", &c, s1, s2);

    if (s1[1] == s2[1]) {
        if (f(s1[0]) > f(s2[0])) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    } else if (s1[1] == c || s2[1] == c) {
        if (s1[1] == c) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    } else {
        printf("NO\n");
    }

    return 0;
}

#include <stdio.h>

typedef struct dupla {
	char card;
	int value;
} cell;

cell celula[9];

void start ();
int beats (char c1, char c2);

int main () {
	char trump, c1, c2, s1, s2;

	scanf ("%c", &trump);
	scanf ("%c", &c1);
	scanf ("%c", &c1);
	scanf ("%c", &s1);
	scanf ("%c", &c2);
	scanf ("%c", &c2);
	scanf ("%c", &s2);

	start ();

	if (s1 == trump && s2 == trump) {
		if (beats (c1, c2))
			printf ("YES");
		else
			printf ("NO");
	}
	else { /*nao todas sao trunfo*/
		if (s1 == trump) /*primeira eh trunfo*/
			printf ("YES");
		else /*primeira nao eh trunfo*/
			if (s2 == trump) /*segunda eh trunfo*/
				printf ("NO");
			else /*segunda TB nao eh trunfo*/
				if (s1 != s2) /*naipes diferentes*/
					printf ("NO");
				else /*naipes iguais*/
					if (beats (c1, c2))
						printf ("YES");
					else
						printf ("NO");
	}
	return 0;
}

void start () {
	int i;

	celula[0].card = '6';
	celula[1].card = '7';
	celula[2].card = '8';
	celula[3].card = '9';
	celula[4].card = 'T';
	celula[5].card = 'J';
	celula[6].card = 'Q';
	celula[7].card = 'K';
	celula[8].card = 'A';

	for (i = 0; i < 9; i++)
		celula[i].value = i;
}

int beats (char c1, char c2) {
	int i, v1, v2;

/*	for (i = 0; i < 9; i++)*/
/*		printf ("%c | %d\n", celula[i].card, celula[i].value);*/

	for (i = 0; i < 9; i++) {

		if (celula[i].card == c1) {
			v1 = celula[i].value;
/*			printf ("1 ---> i = %d e v1 = %d", i, celula[i].value);*/
		}
		if (celula[i].card == c2) {
			v2 = celula[i].value;
/*			printf ("2 ---> i = %d e v2 = %d", i, celula[i].value);*/
		}
	}
	if (v1 > v2) return 1;
	else return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX
void correct(char *a)
{
   char no[]={"TJQKA"};
   char *p;
   if(p=strchr(no,a[0])){
      //      printf("replaced %c by %d\n",a[0],'9'+p-no+1-'0');
      a[0]='9'+p-no+1;
   }
}
int main()
{
   char trump[10],f[10],s[10];

   scanf("%s%s%s",trump,f,s);
   correct(f);
   correct(s);

   if(f[1]==s[1]){
      if(f[0]>s[0])
         puts("YES");
      else puts("NO");
   }
   else if(f[1]==trump[0])
      puts("YES");
   else
      puts("NO");
   return 0;
}

/*
#include <stdio.h>
#include <stdlib.h>
int min(int a, int b) {

    return (a > b) ? b : a;

}

int main() {

    int n, m, a, b;

    scanf("%d %d %d %d", &n, &m, &a, &b);
    int price = 0;

    int c=a*m;
    int d, e, f, g, h, k, l;
    if(c<b||c==b) printf("%d",a*n);
    else if(c>b){
        if(n%m==0) printf("%d", b*(n/m));
        else if(n%m!=0){
            d=n/m+1;
            e=d*b;

            f=n%m;
            g=f*a;
            h=n/m;
            k=h*b;
            l=g+k;
            printf("%d",min(e,l));
        }
    }

    return 0;
}
*/
/*
#include <stdio.h>
#include <stdlib.h>

int main() {

    int sum;
    scanf("%d", &sum);

    if (sum >= 0) {
        printf("%d",sum);
    } else {
        int a = -sum/10%10;
        int b = -sum%10;
        printf("%d",a > b ? sum/100*10-b : sum/10);
    }

    return 0;

}*/
/*
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int x1, y1, x2, y2;

    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if(abs(x1-x2)==abs(y1-y2))
        printf("%d %d %d %d", x1, y2, x2, y1);
    else if(x1 == x2 || y1 == y2) {

        float l = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));

        if(x1==x2) {
            printf("%d %d %d %d", x1+(int)l, y1, x1+(int)l, y2);
        } else
            printf("%d %d %d %d", x1, y1+(int)l, x2, y2+(int)l);
    } else
    printf("-1");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int** matrix, int n) {

    int done = 0;

    while(!done) {

        done = 1;

        for(int i = 0; i < n -1; i++) {

            if((float) matrix[i][1] / matrix[i][0] < (float) matrix[i + 1][1] / matrix[i + 1][0]) {

                int aux1 = matrix[i][0];
                int aux2 = matrix[i][1];

                matrix[i][0] = matrix[i + 1][0];
                matrix[i][1] = matrix[i + 1][1];

                matrix[i + 1][0] = aux1;
                matrix[i + 1][1] = aux2;

                done = 0;

            }
        }
    }
}

int main() {

    int n, strength;

    scanf("%d %d", &strength, &n);

    int** matrix = (int**)malloc(sizeof(int*) * n);

    for(int i = 0; i < n; i++)
        matrix[i] = (int*)malloc(4 * 2);

    for(int i = 0; i < n; i++)
        scanf("%d %d", &matrix[i][0], &matrix[i][1]);

    sort(matrix, n);

    for(int j = 0; j < n; j++)
        for(int i = 0; i < n; i++) {

            if(strength > matrix[i][0] && matrix[i][0] != -1) {

                strength += matrix[i][1];
                matrix[i][0] = -1;

            }
        }

    int finish = 0;

    for(int i = 0; i < n; i++)
        if(matrix[i][0] != -1)
            finish = 1;

    if(!finish)
        printf("YES");
    else
        printf("NO");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, m;

    scanf("%d %d", &n, &m);

    int cnt = (n + 1) / 2;
    int ans = (cnt  + m - 1) / m * m;

    if (ans > n) {
        ans = -1;
    }
    printf("%d", ans);

return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int min(int a, int b) {

    return (a > b) ? b : a;

}

int main() {

    int n;
    scanf("%d", &n);

    int array[n + 1];

    int m1 = 0, m2 = 0, m3 = 0;

    for(int i = 1; i <= n; i++) {

        scanf("%d", &array[i]);

        switch(array[i]) {

        case 1:
            m1++;
            break;

        case 2:
            m2++;
            break;

        case 3:
            m3++;
            break;

        }
    }
    int minim = min(m1, m2);
    minim = min(minim, m3);

    int aux[4];
    int k = 0;

    printf("%d\n", minim);

    for(int i = 0; i < minim; i++) {

        k=1;

        for(int j = 1; k < 4; j++) {

            if(j == n + 1)
                j = 1;

            if(array[j] == k) {

                aux[k++] = j;
                array[j] = -1;

            }
        }

        for(int j = 1; j < k; j++)
            printf("%d ", aux[j]);
        printf("\n");

    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int n, int array[n]) {

    int done = 0;

    while(!done) {

        done = 1;

        for(int i = 0; i < n - 1; i++) {

            if(array[i] > array[i + 1]) {

                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
                done = 0;

            }
        }
    }
}
int main() {

    int n, d;
    scanf("%d %d", &n, &d);

    int array[n];
    int sum = 0;
    for(int i = 0; i < n; i++) {

        scanf("%d", &array[i]);
        sum += array[i];

    }

    sum += 10 * (n - 1);

    if(sum > d)
        printf("-1");
    else {

        //sort(n, array);

        int ct = 2 * (n - 1);
        while(sum + 5 <= d) {

            ct++;
            sum+=5;

        }
        printf("%d", ct);

    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

    int first = 0;
    int last = 1;
    for(int i = 0; i < n; i++) {

        if(i % 2 == 1)
            if(first == 1) {

                printf("#");
                first = 0;

            }
        for(int j = 0; j < m - i % 2; j++) {

            if(i % 2 == 0) {

                printf("#");

            } else
                printf(".");

        }

        if(i % 2 == 1)
            if(last == 1) {

                first = 1;
                printf("#");
                last = 0;

            }

        if(first == 0)
            last = 1;
        printf("\n");
    }

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n;
    scanf("%d", &n);

    int nr;

    int odd = 0;
    int even = 0;
    int pos1 = -1;
    int pos2 = -1;

    for(int i = 0; i < n; i++) {

        scanf("%d", &nr);
        if(nr % 2 == 0) {

            even++;
            pos1 = i + 1;

        } else {

            odd ++;
            pos2 = i + 1;

        }
    }

    if(odd == 1)
        printf("%d", pos2);
    else
        printf("%d", pos1);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void sort(int* array, int size) {

    int done = 0;

    while(!done) {

        done = 1;
        for(int i = 0; i < size - 1; i++)
            if(array[i] > array[i + 1]) {

                int aux = array[i];
                array[i] = array[i + 1];
                array[i + 1] = aux;
                done = 0;

            }
    }
}

int main() {

    int n, v;
    scanf("%d %d", &n, &v);

    int* array = (int*)malloc(sizeof(int) * 50);
    int k;
    int* deals = (int*)malloc(sizeof(int) * 50);
    int sizeDeals = 0;
    int done;
    for(int i = 0; i < n; i++) {

        scanf("%d", &k);
        done = 0;
        for(int j = 0; j < k; j++) {

            scanf("%d", &array[j]);
            if(array[j] < v)
                done = 1;

        }

        if(done)
            deals[sizeDeals++] = i + 1;
        done = 0;

    }

    if(sizeDeals != 0) {

        sort(deals, sizeDeals);
        printf("%d\n", sizeDeals);
        for(int i = 0; i < sizeDeals; i++)
            printf("%d ", deals[i]);

    } else
        printf("0");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;

    scanf("%d", &n);

    char* string = malloc(101);
    char* string1 = malloc(10000);
    char* string2 = malloc(10000);

    for(int i = 0; i <= n; i++) {

        gets(string);
        strcat(string1, string);

    }

    strcpy(string2, string1);
    strrev(string2);

    if(strncmp(string1 + 1, string2, strlen(string2) - 2) == 0)
        printf("YES");
    else
        printf("NO");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n, k;

    scanf("%d %d", &n, &k);
    int maximum = (-1) * (1 << 31);

    for(int i = 0; i < n; i++) {

        int fi, ti;

        scanf("%d %d", &fi, &ti);

        if(k >= ti) {

            if(fi > maximum)
                maximum = fi;

        } else {

            if((fi - (ti - k)) > maximum)
                maximum = fi - (ti - k);

        }

    }

    printf("%d", maximum);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {

        int price, quality;
        scanf("%d %d", &price, &quality);

        if(price != quality) {

            printf("Happy Alex");
            return 0;
        }
    }

    printf("Poor Alex");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int friends, bottles, milliliters, limes, slices, salt, nl, np;
    scanf("%d %d %d %d %d %d %d %d", &friends, &bottles, &milliliters, &limes, &slices, &salt, &nl, &np);

    int allMilliliters = bottles * milliliters / nl / friends;
    int allSalt = salt / np / friends;
    int allLimes = limes * slices / friends;

    int minim = -1;

    minim = (allLimes < allMilliliters) ? allLimes : allMilliliters;
    minim = (minim < allSalt) ? minim : allSalt;

    printf("%d", minim);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int dice1, dice2;
    scanf("%d %d", &dice1, &dice2);

    int dice1Wins = 0;
    int draw = 0;
    int dice2Wins = 0;

    for(int i = 1; i <= 6; i++) {

        if(abs(dice1 - i) > abs(dice2 - i))
            dice2Wins++;
        else if(abs(dice1 - i) < abs(dice2 - i))
            dice1Wins++;
        else
            draw++;

    }

    printf("%d %d %d", dice1Wins, draw, dice2Wins);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);
    int* array = (int*)malloc(n * 4);
    int minimum = (1 << 28);
    int pos;
    for(int i = 0; i < n; i++) {

        scanf("%d", &array[i]);

        if(i > 1) {

            if(array[i] - array[i - 2] < minimum) {

                minimum = array[i] - array[i - 2];
                pos = i - 1;

            }
        }
    }

    minimum = -999999;
    for(int i = 0 ; i < n - 1; i++) {

        if(i + 1 == pos) {
            if(array[i + 2] - array[i] > minimum) {

                minimum = array[i + 2] - array[i];
                i++;

            }
        } else {

            if(array[i + 1] - array[i] > minimum) {

                minimum = array[i + 1] - array[i];

            }

        }
    }

    printf("%d", minimum);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);
    int* exercises = (int*)malloc(sizeof(int) * (n + 1));

    int chest = 0;
    int biceps = 0;
    int back = 0;

    for(int i = 0; i < n; i++) {

        scanf("%d", &exercises[i]);

        switch(i % 3){

        case 0:
            chest += exercises[i];
            break;

        case 1:
            biceps += exercises[i];
            break;

        case 2:
            back += exercises[i];
            break;

        }
    }

    if(chest > back && chest > biceps)
        printf("chest");
    else if(back > chest && back > biceps)
        printf("back");
    else
        printf("biceps");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int cmmdc(int a, int b) {

    int r;

    while(b != 0) {

        r = a % b;
        a = b;
        b = r;

    }

    return a;
}

int main() {

    long int l, r;

    scanf("%ld %ld", &l, &r);
    printf("%d", sizeof(long int));
    if(r - (l += l%2) < 2)
        printf("-1");
    else
        printf("%d %d %d", l, l + 1, l + 2);
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n;
    scanf("%d", &n);

    char matrix[n][n];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            scanf("%c", &matrix[i][j]);

    char diagonal = matrix[0][0];

    for(int i = 0; i < n; i++)
        if(matrix[i][i] != diagonal) {

            printf("NO");
            return 0;

        }
    printf("aaa");
    for(int i = n; i >= 0; i--)
        if(matrix[i][n - i] != diagonal) {

            printf("NO");
            return 0;

        }
    printf("aaa");

    char notDiag = matrix[0][1];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) {

            if(i == j || i + j == n -1)
                j++;
            else {

                if(matrix[i][j] != notDiag) {

                    printf("NO");
                    return 0;

                }
            }
        }

    printf("YES");
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main() {

    int n, m;
    scanf("%d %d", &n, &m);

    char** matrix = (char**)malloc(sizeof(char*) * n);
    for(int i = 0; i < n; i++)
        matrix[i] = malloc(m);

    getchar();

    for(int i = 0; i < n; i++) {

        gets(matrix[i]);
        for(int j = 0; j < m; j++)
            if(matrix[i][j] == '.') {
                if((i + j) % 2 == 0)
                    matrix[i][j] = 'B';
                else
                    matrix[i][j] = 'W';

            }

    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++)
            printf("%c", matrix[i][j]);
        printf("\n");

    }
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int freq1[27], freq2[27];

int main() {

    int n;
    scanf("%d", &n);
    getchar();
    char* question = malloc(15);

    int left = INT_MIN / 2;
    int right = INT_MAX / 2;

    for(int i = 0; i < n && left <= right; i++) {

        gets(question);

            if(question[0] == '>' && question[strlen(question) - 1] == 'Y' ||
               (question[0] == '<' && question[strlen(question) - 1] == 'N')) { /// > or >=

                if(question[1] == '=') {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    left = atoi(tok) + 1;

                } else {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    left = atoi(tok);

                }
            } else if(question[0] == '<' && question[strlen(question) - 1] == 'Y' || (question[0] == '>' && question[strlen(question) - 1] == 'N')) {

                if(question[1] == '=') { /// <=

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    right = atoi(tok);

                } else {

                    char* tok = strtok(question, " ");
                    tok = strtok(NULL, " ");
                    right = atoi(tok) - 1;

                }
            }

        if(question[0] == '>' && question[1] == '=' && question[strlen(question) -1 ] == 'Y' ||
                (question[0] == '<' && question[1] != '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) > left)
                left = atoi(tok);

        } else if(question[0] == '>' && question[1] != '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '<' && question[1] == '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) + 1 > left)
                left = atoi(tok) + 1;

        } else if(question[0] == '<' && question[1] == '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '>' && question[1] != '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) < right)
                right = atoi(tok);

        } else if(question[0] == '<' && question[1] != '=' && question[strlen(question) - 1] == 'Y' ||
                  (question[0] == '>' && question[1] == '=' && question[strlen(question) - 1] == 'N')) {

            char* tok = strtok(question, " ");
            tok = strtok(NULL, " ");
            if(atoi(tok) - 1 < right)
                right = atoi(tok) - 1;

        }
    }

    if(left <= right) {

        printf("%d", right);

    } else
        printf("Impossible");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

void mergeSort(int left, int mid, int right, int* array, int n) {

    int*aux = (int*)malloc(sizeof(int) * n);

    int i = left;
    int j = mid + 1;
    int index = i;

    while(i <= mid && j <= right) {

        if(array[i] > array[j]) {

            aux[index++] = array[i++];

        } else {

            aux[index++] = array[j++];

        }

    }

    for(int l = i; l <= mid; l++)
        aux[index++] = array[l];

    for(int l = j; l <= right; l++)
        aux[index++] = array[l];

    for(int l = left; l <= right; l++)
        array[l] = aux[l];

}

void merge(int left, int right, int* array, int n) {

    int mid;

    if(left < right) {

        mid = (left + right) / 2;
        merge(left, mid, array, n);
        merge(mid + 1, right, array, n);
        mergeSort(left, mid, right, array, n);

    }
}

int main() {

    int devices, sockets, supply;

    scanf("%d %d %d", &supply, &devices, &sockets);
    int array[supply];

    for(int i = 0; i < supply; i++)
        scanf("%d", &array[i]);

    merge(0, supply - 1, array, supply);

    if(devices <= sockets)
        printf("0");
    else {

        int i = 0;
        while(sockets < devices && i < supply) {

            sockets += array[i] - 1;
            i++;

        }

        if(i != supply)
            printf("%d", i);
        else if(sockets >= devices)
            printf("%d", i);
        else
            printf("-1");
    }
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main() {

    int x, y;
    scanf("%d %d", &x, &y);
    int s = 0;
    if(y>x && x>=-y) {

        printf("a");
        s=-2+y*4;

    }

    if(y<x && x<=-y+1) {

        printf("b");
        s=-y*4;

    }

    if(y<=x && x>-y+1) {

        printf("c");
        s=-3+x*4;

    }

    if(y>=x && x<-y) {

        printf("d");
        s=-1-4*x;

    }

    printf("%d", s);

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int max(int a, int b) {

    return (a > b) ? a : b;

}

int main() {

    int a, b, c, d;

    scanf("%d %d %d %d", &a, &b, &c, &d);

    printf("%d %d %d", 2-(a==c||b==d), ((a+b)%2==(c+d)%2)*(2-(a-b==c-d||a+b==c+d)), max(abs(c-a),abs(d-b)));
    return 0;

} */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main() {

    char suit;
    scanf("%c", &suit);
    getchar();

    char* array = malloc(10);
    gets(array);
    char vect[] = "6789TJQKA";
    if(array[1] == suit && array[strlen(array) - 1] != suit ||
       (array[1] == array[strlen(array) - 1] && strchr(vect, array[0]) > strchr(vect, array[strlen(array) - 2])))
        printf("YES");
    else
        printf("NO");

    return 0;

}

#include <stdio.h>
#include <stdlib.h>
/* Written by Nishant Mittal aka nishantwrp */
int check(char a,char b) {
char data[9] = {'6','7','8','9','T','J','Q','K','A'};
int aval,bval;
int i=0;
while(i<9) {
if (a == data[i]) {
    aval = i;
    break;
}
i++;
}
int j=0;
while(j<9) {
if (b == data[j]) {
    bval = j;
    break;
}
j++;
}
if (aval>bval) {
    return 1;
} else {
return 0;
}
return 0;
}
int main()
{
   char trump;
   scanf("%c\n",&trump);
   char crd1[2];
   char crd2[2];
   scanf("%c%c %c%c",&crd1[0],&crd1[1],&crd2[0],&crd2[1]);
   if (crd1[1] == trump && crd2[1] == trump) {
    if (check(crd1[0],crd2[0]) == 1) {
        printf("YES");
    } else {
    printf("NO");
    }
   } else if (crd1[1] == trump) {
   printf("YES");
   } else {
   if (crd1[1] == crd2[1]) {
     if (check(crd1[0],crd2[0]) == 1) {
        printf("YES");
    } else {
    printf("NO");
    }
   } else {
   printf("NO");
   }
   }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

char choose(char ch)
{
	switch (ch)
	{
	case '6':
		ch = '1'; break;
	case '7':
		ch = '2'; break;
	case '8':
		ch = '3'; break;
	case '9':
		ch = '4'; break;
	case 'T':
		ch = '5'; break;
	case 'J':
		ch = '6'; break;
	case 'Q':
		ch = '7'; break;
	case 'K':
		ch = '8'; break;
	case 'A':
		ch = '9'; break;
	}
	return ch;
}

int main()
{
	int n;
	char suit;

	while (~scanf("%c", &suit))
	{
		getchar();
		int flag = 0;
		char ch1[4], ch2[4];
		scanf("%s %s", ch1, ch2);
		getchar();
		ch1[0] = choose(ch1[0]);
		ch2[0] = choose(ch2[0]);

		if (ch1[1] == ch2[1])
		{
			if (ch1[0] > ch2[0])
				flag = 1;
		}
		else if (ch1[1] == suit)
				flag = 1;

		if (flag)
			puts("YES");
		else
			puts("NO");
	}

	return 0;
}

#include<stdio.h>
int s(char c);
int main(){
char a,b,c,d,t;
int i,j;
scanf("%c\n",&t);
scanf("%c%c %c%c",&a,&b,&c,&d);
if(b==t&&d!=t)
    printf("YES\n");
else if(d==t&&b!=t)
    printf(" NO\n");
else{
    i=s(a);
    j=s(c);
    if(b==d&&i-j>0)
      printf("YES\n");
    else
    printf("NO\n");
}
return 0;
}
int s(char c){
if('5'<c&&c<='9')
    return c-'0';
if(c=='T')
    return 10;
if(c=='J')
    return 11;
if(c=='K')
    return 13;
if(c=='A')
    return 14;
if(c=='Q')
    return 12;
}

#include<stdio.h>

char trump,ch1[2],ch2[2];

int main(void)
{
	int i,a,b,x;
	char ch[10]={'6','7','8','9','T','J','Q','K','A'};
	scanf("%c",&trump);
	x=trump;
	scanf("%s %s",ch1,ch2);
	for(i=0;i<10;i++) {
		if(ch1[0]==ch[i])
			a=i;
		else if(ch2[0]==ch[i])
			b=i;
	}

	if(ch1[1]==ch2[1]) {
		if(a>b)
			printf("YES");
		else
			printf("NO");
	}
	else {
		if(ch1[1]==x && ch2[1]!=x)
			printf("YES");
		else
			printf("NO");
	}

	return 0;
}

#include<stdio.h>
int main()
{
	char strSuit;
	char strCard1[3], strCard2[3];
	scanf("%c",&strSuit);
	scanf("%s %s",strCard1, strCard2);
	if(strCard1[0]=='6')
		strCard1[0]='1';
	else if(strCard1[0]=='7')
		strCard1[0]='2';
	else if(strCard1[0]=='8')
		strCard1[0]='3';
	else if(strCard1[0]=='9')
		strCard1[0]='4';
	else if(strCard1[0]=='T')
		strCard1[0]='5';
	else if(strCard1[0]=='J')
		strCard1[0]='6';
	else if(strCard1[0]=='Q')
		strCard1[0]='7';
	else if(strCard1[0]=='K')
		strCard1[0]='8';
	else if(strCard1[0]=='A')
		strCard1[0]='9';

	if(strCard2[0]=='6')
		strCard2[0]='1';
	else if(strCard2[0]=='7')
		strCard2[0]='2';
	else if(strCard2[0]=='8')
		strCard2[0]='3';
	else if(strCard2[0]=='9')
		strCard2[0]='4';
	else if(strCard2[0]=='T')
		strCard2[0]='5';
	else if(strCard2[0]=='J')
		strCard2[0]='6';
	else if(strCard2[0]=='Q')
		strCard2[0]='7';
	else if(strCard2[0]=='K')
		strCard2[0]='8';
	else if(strCard2[0]=='A')
		strCard2[0]='9';

	if(strCard1[1]==strSuit&&strCard2[1]!=strSuit)
		printf("YES\n");
	else if(strCard1[1]==strCard2[1])
	{
		if((int)strCard1[0]-(int)strCard2[0]>0)
			printf("YES\n");
		else
			printf("NO\n");
	}
	else
		printf("NO\n");

	return 0;
}

#include <stdio.h>
                                                        //CARD GAME
int main()
{
    char trump ;
    char first_set[3], second_set[3] ;
    char rank[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'} ;

    scanf("%c", &trump);
    scanf("%s %s", first_set, second_set);

    if(first_set[1] == trump && second_set[1] != trump)
        printf("YES\n");

    else if(first_set[1] != trump && second_set[1] == trump)
        printf("NO\n");

    else
    {
        int rank_first=0, rank_second=0 ;
        int i ;

        for(i=0; i<9; ++i)
        {
            if(rank[i] == first_set[0])
                rank_first = i ;

            if(rank[i] == second_set[0])
                rank_second = i ;
        }

        if(rank_first > rank_second && (first_set[1] == second_set[1]))
            printf("YES\n");

        else
            printf("NO\n");
    }

    return 0 ;
}

#include <stdio.h>
#include <string.h>

int main() {
    char trump, a[8], b[8];
    const char rank[] = "6789TJQKA";

    scanf("%c%s%s", &trump, a, b);
    puts((a[1] == b[1] && strchr(rank, a[0]) > strchr(rank, b[0])) || (a[1] == trump && b[1] != trump) ? "YES" : "NO");

    return 0;
}

#include <stdio.h>

int main()
{
    int i,check1=0,check2=0;
    char str[]="6789TJQKA";
    char str_trump[]="SHDC",trump,str1[3],str2[3];
    scanf("%c",&trump);
    getchar();
    gets(str1);
    gets(str2);
    //getchar();
    for(i=0; i<strlen(str);i++)
    {
        if(str[i]==str1[0])
            check1=i;
        if(str[i]==str2[0])
            check2=i;
    }
    if(str1[1]==trump && str2[1]==trump)
    {
        if(check1>check2)
            printf("YES");
        else
            printf("NO");
    }
    else if(str1[1]==trump && str2[1]!=trump)
    {
        printf("YES");
    }
    else if(str1[1]!=trump && str2[1]==trump)
    {
        printf("NO");
    }
    //int check3=0,check4=0;
    else if(str1[1]==str2[1])
    {
        if(check1>check2)
            printf("YES");
        else
            printf("NO");
    }
    else
        printf("NO");
    return 0;
}

#include <stdio.h>
#include <string.h>

int main()
{
    char card1[3], card2[3], trump[2], *cards = "6789TJQKA";
    scanf("%s%s%s", trump, card1, card2);
    if (card1[1] == card2[1])
    {
        if ((strchr(cards, card1[0]) - cards) > (strchr(cards, card2[0]) - cards))
            printf("YES");
        else printf("NO");
    }
    else if (card1[1] == trump[0])
        printf("YES");
    else printf("NO");
    return 0;
}

#include <stdio.h>

int tranfCartaParaOrdemDeCarta(char c) {
	switch (c) {
		case 'T': return 10;
		case 'J': return 12;
		case 'Q': return 13;
		case 'K': return 14;
		case 'A': return 15;
		default:
			return (c-'0');
	}
}

void cardGame() {
	char c, s[2][3];

	scanf("%c", &c);
	scanf("%s %s", s[0], s[1]);

	if (s[0][1] == s[1][1]) {
		if (tranfCartaParaOrdemDeCarta(s[0][0]) > tranfCartaParaOrdemDeCarta(s[1][0]))
			printf("YES\n");
		else
			printf("NO\n");
	}
	else if (s[0][1] == c)
		printf("YES\n");
	else
		printf("NO\n");
}

int main() {

	cardGame();
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int higher_card( char ch)
{
    int i;
    char cards[9] = "6789TJQKA";
    for(i=0; i<9; i++){
        if(cards[i] == ch) return i;
    }
    return 0;
}

int main(void)
{
    char trump;
    char card_1[3], card_2[3];
    trump = getchar();

    scanf("%s %s", card_1, card_2);

    if(card_1[1] == trump && card_2[1]!= trump) printf("YES") ;
    else if(card_1[1] == card_2[1]){
        if(higher_card(card_1[0]) > higher_card(card_2[0])) printf("YES");
        else printf("NO");
    }
    else printf("NO");
    return 0;
}

#include<stdio.h>
int number(char a){
    if(a>='6' && a<='9'){
        return a-'6';
    }else if(a=='T'){
        return 4;
    }else if(a=='J'){
        return 5;
    }else if(a=='Q'){
        return 6;
    }else if(a=='K'){
        return 7;
    }else if(a=='A'){
        return 8;
    }else{
        return -1;
    }
}
int main() {
    char suit[2];
    char card1[3];
    char card2[3];
    scanf("%s",suit);
    scanf("%s%s",card1,card2);
    int is_beat=0;
    if(card1[1]==suit[0] && card2[1]!=suit[0]){
        is_beat=1;
    }else if(card1[1]==card2[1]){
        if(number(card1[0])>number(card2[0])){
            is_beat=1;
        }
    }
    if(is_beat) printf("YES\n");
    else printf("NO\n");
    return 0;
}

#include<stdio.h>
#include<ctype.h>
char s[9] = {'6','7','8','9','T','J','Q','K','A'};
int chiso(char c)
{
	int i;
	for(i=0;i<=8;i++)
		if(s[i]==c)
			break;
	return i;
}
void check(char s1[],char s2[],char trump)
{
	if(s1[1]==s2[1])
	{
		if(chiso(s1[0])>chiso(s2[0])) printf("YES\n");
		else printf("NO\n");
	}
	else
	if(s1[1]==trump)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}

}

int main()
{
	char trump;
	char s1[3];
	char s2[3];
	scanf("%c\n",&trump);
	scanf("%s %s",s1,s2);
	check(s1,s2,trump);
	return 0;
}

#include <stdio.h>

void convRank(char *rank) {
  switch (*rank) {
  case 'T':
    *rank = '9' + 1;
    break;
  case 'J':
    *rank = '9' + 2;
    break;
  case 'Q':
    *rank = '9' + 3;
    break;
  case 'K':
    *rank = '9' + 4;
    break;
  case 'A':
    *rank = '9' + 5;
    break;
  default:
    break;
  }
}

int main(int argc, char **argv) {
  char trump, suit1, rank1, suit2, rank2;

  scanf("%c\n", &trump);
  scanf("%c%c %c%c", &rank1, &suit1, &rank2, &suit2);
  convRank(&rank1);
  convRank(&rank2);

  if ( (suit1 == trump && suit2 != trump) ||
       (suit1 == suit2 && rank1 > rank2) )
       printf("YES");
  else printf("NO");
  return 0;
}

#include <stdio.h>

typedef struct {
    int rank;
    char suit;
    int trump;      /* o naipe dessa carte e' o trump? */
} Carta;

int rank(char r) {
    switch(r) {
        case 'T':
            return 10;
        case 'J':
            return 11;
        case 'Q':
            return 12;
        case 'K':
            return 13;
        case 'A':
            return 14;
        default:
            return (r - '0');
    }
}

Carta le_carta(char trump) {
    Carta c;
    char r;
    scanf("%c %c", &r, &c.suit);
    c.rank = rank(r);
    c.trump = (c.suit == trump) ? 1 : 0;
    return c;
}

int main() {
    char trump;
    Carta c1, c2;

    scanf("%c\n", &trump);
    c1 = le_carta(trump);
    getchar();
    c2 = le_carta(trump);

    if ((c1.trump > c2.trump)
        || ((c1.suit == c2.suit) && (c1.rank > c2.rank)))
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

// Code Forces 106A
#include<stdio.h>
#define T 10
#define J 11
#define Q 12
#define K 13
#define A 14
int main()
{
    char trump,C0,C1,B0,B1;
    scanf("%c\n%c%c\n%c%c",&trump,&C0,&C1,&B0,&B1);
    //printf("after scan:%c%c%c%c%c\n",trump,C0,C1,B0,B1);
    if((C1==trump)&&(B1!=trump)) {printf("YES\n");return 0;}
    if((C1!=trump)&&(B1==trump)) {printf("NO\n");return 0;}
    if(C0>B0) printf("YES\n");
    else printf("NO\n");
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<math.h>
int cardrank(char rankx)
{int i;
	char rank[]={'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
	for(i=0;rank[i]!='\0';i++)
	{
		if(rankx==rank[i])return i;
	}
	return -1;
}
int main()
{
	char trump,suit1,rank1,suit2,rank2;int r1,r2,i;

	scanf("%c %c %c %c %c",&trump,&rank1,&suit1,&rank2,&suit2);
	r1=cardrank(rank1);r2=cardrank(r2);
	if(suit1==trump){printf("YES");return 0;}
	else if(suit1==suit2){
		if(r1>r2){printf("YES");return 0;}
		else if(r2>r2){printf("NO");return 0;}
	}

printf("NO");
return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:38:10 GMT 2011 *******/

#include <stdio.h>

 int value_converter(char temp){
    if(temp=='6'){
        return 6;
    }
    else if(temp=='7'){
        return 7;
    }
    else if(temp=='8'){
        return 8;
    }
    else if(temp=='9'){
        return 9;
    }
    else if(temp=='T'){
        return 10;
    }
    else if(temp=='J'){
        return 11;
    }
    else if(temp=='Q'){
        return 12;
    }
    else if(temp=='K'){
        return 13;
    }
    else if(temp=='A'){
        return 14;
    }
}

 int main()
 {

    char trump, p1, p2 , p3, p4;

    scanf("%c\n", &trump);
    scanf("%c%c %c%c", &p1,&p2,&p3,&p4);

    int integer_value_of_p11 = value_converter(p1);
    int integer_value_of_p21 = value_converter(p3);
    if(trump==p2 && trump==p4 && integer_value_of_p11 > integer_value_of_p21) {
       printf("YES");
   }
   else if(trump==p2 && trump==p4 && integer_value_of_p11 < integer_value_of_p21) {
       printf("NO");
   }
   else if(trump==p2) {
       printf("YES");
   }
   else if(trump==p4) {
       printf("NO");
   }
   else if( integer_value_of_p11 > integer_value_of_p21 ) {
       printf("YES");
   } else if( integer_value_of_p11 < integer_value_of_p21 ) {
       printf("NO");
   }
   else if(integer_value_of_p11 == integer_value_of_p21){
   printf("NO");
   }

return 0;
}

#include <stdio.h>

int power(char,char,char);
int main()
{
    char trump,rank1,rank2,suit1,suit2;
    int power1=0,power2=0;

    scanf(" %c",&trump);
    scanf(" %c%c %c%c",&rank1,&suit1,&rank2,&suit2);
    power1=power(trump,rank1,suit1);
    power2=power(trump,rank2,suit2);
    /*printf("%d %d",power1,power2);*/
    if(power1>power2)
       printf("YES");
    else
       printf("NO");

    /*printf("%c %c %c %c %c",trump,rank1,suit1,rank2,suit2);*/
    /*system("pause");*/
    return 0;
}
int power(char trump,char rank,char suit)
{
   int power;

   switch(rank)
   {
      case '6':
         power=6;
         break;
      case '7':
         power=7;
         break;
      case '8':
         power=8;
         break;
      case '9':
         power=9;
         break;
      case 'T':
      case 't':
         power=10;
         break;
      case 'J':
      case 'j':
         power=11;
         break;
      case 'Q':
      case 'q':
         power=12;
         break;
      case 'K':
      case 'k':
         power=13;
         break;
      case 'A':
      case 'a':
         power=14;
         break;
   }
    if(suit == trump || suit == trump+32 || suit == trump-32)
       power+=10;

    return power;
}
/****** PCCA -Tue Oct 18 12:49:02 GMT 2011 *******/

#include <stdio.h>
#include <string.h>

char Base[9]="6789TJQKA";
char A[3],B[3];
char T;

int Judge()
{
    int i,j;
    for(i=0; Base[i]!=A[0]; ++i);
    for(j=0; Base[j]!=B[0]; ++j);
    if(A[1]==B[1]&&i>j)
    {
        return 1;
    }
    return 0;
}

int main()
{
    scanf("%c %s %s",&T,A,B);
    if(A[1]==T||Judge ())
    {
        puts("YES");
        return 0;
    }
    puts("NO");
    return 0;
}

#include <stdio.h>
int main(){
char trump,a[2],b[2];
scanf("%c",&trump);
scanf("%s%s",a,b);
if(a[1]==trump&&b[1]!=trump)printf("YES");
else if(a[1]!=trump&&b[1]==trump)printf("NO");
else {
if(a[0]-b[0]>0)printf("YES");
else printf("NO");
}
return 0;
}

#include <stdio.h>

int tranfCartaParaOrdemDeCarta(char c) {
	switch (c) {
		case 'T': return 1;
		case 'J': return 2;
		case 'Q': return 3;
		case 'K': return 4;
		case 'A': return 5;
		default:
			return EOF;
	}
}

void cardGame() {
	char c, s[2][2];

	scanf("%c", &c);
	scanf("%s %s", s[0], s[1]);

	if (s[0][1] == s[1][1]) {
		if (tranfCartaParaOrdemDeCarta(s[0][0]) > tranfCartaParaOrdemDeCarta(s[1][0]))
			printf("YES\n");
		else
			printf("NO\n");
	}
	else if (s[0][1] == c)
		printf("YES\n");
	else
		printf("NO\n");
}

int main() {

	cardGame();
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num[]={6,7,8,9,10,11,12,13,14};
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else
                {
                        if(compare_1[0]>compare_2[0])
                        {
                        printf("YES");
                        return 0;
                        }
                        else
                        {
                        printf("NO");
                        return 0;
                        }
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 05:51:28 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:38:19 GMT 2011 *******/

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int main()
{
        char c,a[3],b[3];
        char p[9][1]={'6', '7', '8', '9', 'T', 'J', 'Q', 'K' , 'A'};
        scanf("%c",&c);
        scanf("%s %s",&a,&b);
        if(a[1]==c && b[1]!=c)
        printf("YES");
        else
        {
                int x=0,y=0;
                for(int i=0;i<9;i++)
                {
                        if(a[0]==p[i][0])
                        x=i;
                        else if(b[0]==p[i][0])
                        y=i;
                }
                if(x>=y)
                printf("YES");
                else
                printf("NO");
        }
        return 0;
}

#include <stdio.h>
#include <stdlib.h>

/*
6 7 8 9 T J Q K A
S H D C
*/

/* Devolve o valor da carta em numero inteiro */
int cardValue(char card) {
	if(card == '6') return 6;
	if(card == '7') return 7;
	if(card == '8') return 8;
	if(card == '9') return 9;
	if(card == 'T') return 10;
	if(card == 'J') return 11;
	if(card == 'Q') return 12;
	if(card == 'K') return 13;
	if(card == 'A') return 14;
	return -1;
}

/* Devolve 1 se a primeira carta for maior
			0 se for igual cc
*/
int isHigher(char first, char second) {
	if(cardValue(first) > cardValue(second)) return 1;
	else return 0;
	return -1;
}

int main() {
	char trump;
	char *firstCard;
	char *secondCard;
	firstCard = malloc(2*sizeof(char));
	secondCard = malloc(2*sizeof(char));
	scanf("%c %s %s", &trump, firstCard, secondCard);
	if(trump == firstCard[1]) {
		printf("YES");
	}
	else if(firstCard[1] == secondCard[1] &&
			isHigher(firstCard[0], secondCard[0])) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

#include <stdio.h>

int tranfCartaParaOrdemDeCarta(char c) {
	switch (c) {
		case 'T': return 1;
		case 'J': return 2;
		case 'Q': return 3;
		case 'K': return 4;
		case 'A': return 5;
		default:
			return c;
	}
}

void cardGame() {
	char c, s[2][2];

	scanf("%c", &c);
	scanf("%s %s", s[0], s[1]);

	if (s[0][1] == s[1][1]) {
		if (tranfCartaParaOrdemDeCarta(s[0][0]) > tranfCartaParaOrdemDeCarta(s[1][0]))
			printf("YES\n");
		else
			printf("NO\n");
	}
	else if (s[0][1] == c)
		printf("YES\n");
	else
		printf("NO\n");
}

int main() {

	cardGame();
	return 0;
}

#include <stdio.h>

int dec(char c){
	switch(c){
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	case 'T': return 10;
	case 'J': return 11;
	case 'Q': return 12;
	case 'K': return 13;
	case 'A': return 15;
	}
}

int istrump(char trump,char this){
	if(trump==this)return 1;
	else return 0;
}

int main(void)
{
        char a,b,c,d,e;
        int scorea,scoreb;
        int win;
        scanf(" %c",&a);
        fflush(stdin);
        scanf("%c%c %c%c",&b,&c,&d,&e);
        if(istrump(a,c)){
                if(istrump(a,e)){
                        if(dec(b)>=dec(d))win=1;
                        else win=0;
                }
                else win=1;
        }
        else{
                if(c==e){
                        if(dec(b)>=dec(d))win=1;
                        else win=0;
                }
                else if(istrump(a,e)){
                        win=0;
                }
                else win=0;
        }

        if(win)puts("YES");
        else puts("NO");

        return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	char a, b, c, d, e;
	a = getchar();
	getchar();
	b = getchar();
	c = getchar();
	getchar();
	d = getchar();
	e = getchar();
	if (c == a)
		printf("YES\n");
	else if (c == e)
		printf("YES\n");
	else
		printf("NO\n");
}

#include<stdio.h>
int main()
{char str[2][3]={'\0'},ch;int i,m[2]={0};

scanf("%c",&ch);
for(i=0;i<2;i++)
{scanf("%s",str[i]);
switch(str[i][0])
{case '6':m[i]=6;break;
case '7':m[i]=7;break;
case '8':m[i]=8;break;
case '9':m[i]=9;break;
case 'T':m[i]=10;break;
case 'J':m[i]=11;break;
case 'Q':m[i]=12;break;
case 'K':m[i]=13;break;
case 'A':m[i]=14;break;}}
if(str[0][1]==ch)
{if(str[1][1]==ch)
{if(m[0]>m[1])
printf("YES");
else
printf("NO");
}
else
printf("YES");
}
else
{if(str[1][1]==ch)
printf("NO");
else
{if(m[0]>m[1])
printf("YES");
else
printf("NO");
}}
return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:41:33 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump[]="SHDC";
    int num[]={6,7,8,9,10,11,12,13,14};
    char trump_in;
    char compare_1[2];
    char compare_2[2];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);
    for(i=0;i<4;i++)
    {
        if(trump[i]==compare_1[2] && trump[i]==compare_2[2])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    }
    return 0;
}
/****** PCCA -Thu Dec 08 14:21:56 GMT 2011 *******/

// Code Forces 106A
#include<stdio.h>
#define T 10
#define J 11
#define Q 12
#define K 13
#define A 14
int main()
{
    char trump;
    char Arr[2]={'0'};
    char Brr[2]={'0'};
    scanf("%c%c%c%c%c",&trump,&Arr[0],&Arr[1],&Brr[0],&Brr[1]);
    if((Arr[1]==trump)&&(Brr[1]!=trump)) {printf("YES\n");return 0;}
    if((Arr[1]!=trump)&&(Brr[1]==trump)) {printf("NO\n");return 0;}
    if(Arr[0]>Brr[0]) printf("YES\n");
    else printf("NO\n");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num[]={6,7,8,9,10,11,12,13,14};
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else
                {
                        if(compare_1[0]>compare_2[0])
                        {
                        printf("YES");
                        return 0;
                        }
                        else
                        {
                        printf("NO");
                        return 0;
                        }
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 05:51:44 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:41:24 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:38:30 GMT 2011 *******/

#include <stdio.h>
#include <string.h>
int main()
{
     char a,b,c,d,e;
     scanf("%c",&e);
     int j,k,l;
     scanf("%c%c %c%c",&a,&b,&c,&d);
     char ch[9]={'6','7','8','9','T','J','Q','K','A'};
     if(b!=e || d!=e)
     {
          for(int i=0;i<9;i++)
          {
               if(ch[i]==a)
               j=i;
               if(ch[i]==c)
               k=i;

          }
          if(j>k)
          printf("YES");
          else
          printf("NO");
     }
   else if(b!=d &&( b==e || d==e))
     printf("YES");
     else
     printf("NO");
}

#include <stdio.h>

int power(char,char,char);
int main()
{
    char trump,rank1,rank2,suit1,suit2;
    int power1=0,power2=0;

    scanf(" %c",&trump);
    scanf(" %c%c %c%c",&rank1,&suit1,&rank2,&suit2);
    power1=power(trump,rank1,suit1);
    power2=power(trump,rank2,suit2);
    /*printf("%d %d",power1,power2);*/
    if(power1>power2)
       printf("YES");
    else
       printf("NO");

    /*printf("%c %c %c %c %c",trump,rank1,suit1,rank2,suit2);*/
    return 0;
}
int power(char trump,char rank,char suit)
{
    int power;

    switch(rank)
    {
       case '6':
          power=6;
          break;
       case '7':
          power=7;
          break;
       case '8':
          power=8;
          break;
       case '9':
          power=9;
          break;
       case 'T':
          power=10;
          break;
       case 'J':
          power=11;
          break;
       case 'Q':
          power=12;
          break;
       case 'K':
          power=13;
          break;
       case 'A':
          power=14;
          break;
    }
    if(suit==trump)
       power+=10;

    return power;
}
/****** PCCA -Tue Oct 18 12:37:27 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                        if(compare_1[0]>compare_2[0])
                        {
                        printf("YES");
                        return 0;
                        }
                        else
                        {
                        printf("NO");
                        return 0;
                        }
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 08:57:33 GMT 2011 *******/

// Code Forces 106A
#include<stdio.h>
int main()
{char trump,C0,C1,B0,B1;int camp1,camp2;
    scanf("%c\n%c%c\n%c%c",&trump,&C0,&C1,&B0,&B1);camp1=C0,camp2=B0;
    if((C1==trump)&&(B1!=trump)) {printf("YES\n");return 0;}
    if((C1!=trump)&&(B1==trump)) {printf("NO\n");return 0;}
    if(C0=='T') camp1='a';if(C0=='J') camp1='b';if(C0=='Q') camp1='c';if(C0=='K') camp1='d';if(C0=='A') camp1='e';
    if(B0=='T') camp2='a';if(B0=='J') camp2='b';if(B0=='Q') camp2='c';if(B0=='K') camp2='d';if(B0=='A') camp2='e';
    if(camp1>camp2)printf("YES\n");else printf("NO\n");
    return 0;}

#include<stdio.h>
int main()
{
	char strSuit;
	char strCard1[3], strCard2[3];
	scanf("%c",&strSuit);
	scanf("%s %s",strCard1, strCard2);
	if(strCard1[1]==strSuit||strCard1[1]==strCard2[1])
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:41:04 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

/*
6 7 8 9 T J Q K A
S H D C
*/

/* Devolve o valor da carta em numero inteiro */
int cardValue(char card) {
	if(card == '6') return 6;
	if(card == '7') return 7;
	if(card == '8') return 8;
	if(card == '9') return 9;
	if(card == 'T') return 10;
	if(card == 'J') return 11;
	if(card == 'Q') return 12;
	if(card == 'K') return 13;
	if(card == 'A') return 14;
	return -1;
}

/* Devolve 1 se a primeira carta for maior
			0 se for igual cc
*/
int isHigher(char first, char second) {
	if(cardValue(first) > cardValue(second)) return 1;
	else return 0;
	return -1;
}

int main() {
	char trump;
	char *firstCard;
	char *secondCard;
	firstCard = malloc(2*sizeof(char));
	secondCard = malloc(2*sizeof(char));
	scanf("%c %s %s", &trump, firstCard, secondCard);
	if(firstCard[1] == secondCard[1] &&
			isHigher(firstCard[0], secondCard[0])) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:37:50 GMT 2011 *******/

// Code Forces 106A
#include<stdio.h>
int main()
{char trump,C0,C1,B0,B1;int camp1,camp2;
    scanf("%c\n%c%c\n%c%c",&trump,&C0,&C1,&B0,&B1);camp1=C0,camp2=B0;
    if((C1==trump)&&(B1!=trump)) {printf("YES\n");return 0;}
    if((C1!=trump)&&(B1==trump)) {printf("NO\n");return 0;}
    if(C0=='T') camp1=10;if(C0=='J') camp1=11;if(C0=='Q') camp1=12;if(C0=='K') camp1=13;if(C0=='A') camp1=14;
    if(B0=='T') camp2=10;if(B0=='J') camp2=11;if(B0=='Q') camp2=12;if(B0=='K') camp2=13;if(B0=='A') camp2=14;
    if(camp1>camp2)printf("YES\n");else printf("NO\n");
    return 0;}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                    if(compare_1[1]==compare_2[1])
                    {
                        if(compare_1[0]>compare_2[0])
                        {
                        printf("YES");
                        return 0;
                        }
                        else
                        {
                        printf("NO");
                        return 0;
                        }
                    }
                    else if(compare_1[1]>compare_2[1])
                    {
                        printf("YES");
                        return 0;
                    }
                    else
                    {
                        printf("NO");
                        return 0;
                    }
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 11:00:20 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                    if(compare_1[1]==compare_2[1])
                    {
                        if(compare_1[0]>compare_2[0])
                        {
                        printf("YES");
                        return 0;
                        }
                        else
                        {
                        printf("NO");
                        return 0;
                        }
                    }
                    else if(compare_1[1]>compare_2[1])
                    {
                        printf("YES");
                        return 0;
                    }
                    else
                    {
                        printf("NO");
                        return 0;
                    }
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 10:59:57 GMT 2011 *******/

#include <stdio.h>
#include <stdlib.h>

/*
6 7 8 9 T J Q K A
S H D C
*/

/* Devolve o valor da carta em numero inteiro */
int cardValue(char card) {
	if(card == '6') return 6;
	if(card == '7') return 7;
	if(card == '8') return 8;
	if(card == '9') return 9;
	if(card == 'T') return 10;
	if(card == 'J') return 11;
	if(card == 'Q') return 12;
	if(card == 'K') return 13;
	if(card == 'A') return 14;
	return -1;
}

/* Devolve 1 se a primeira carta for maior
			0 se for igual cc
*/
int isHigher(char first, char second) {
	if(cardValue(first) > cardValue(second)) return 1;
	else return 0;
	return -1;
}

int main() {
	char trump;
	char *firstCard;
	char *secondCard;
	firstCard = malloc(2*sizeof(char));
	secondCard = malloc(2*sizeof(char));
	scanf("%c %s %s", &trump, firstCard, secondCard);
	if(trump == firstCard[1]) {
		printf("YES");
	}
	else if(trump == secondCard[1]) {
		printf("YES");
	}
	else if(firstCard[1] == secondCard[1] &&
			isHigher(firstCard[0], secondCard[0])) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:38:01 GMT 2011 *******/

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>

#define T 10
#define J 11
#define Q 12
#define K 13
#define A 14
int main()
{
char t;
char s1[2],s2[2];
int a[25]={0};
scanf("%c",&t);
scanf("%s %s",s1,s2);
if(s1[1]==t&&s2[1]!=t)
{printf("YES");
return 0;
}
if(s1[1]==s2[1]&&s1[0]>s2[0])
{printf("YES");
return 0;
}
printf("NO");

return 0;
}

#include<stdio.h>
int main()
{
	char p,arr[6],a,b;
	char str[10]={'0','6','7','8','9','T','J','Q','K','A'
	};
	int i,j,k,l;
	scanf("%c",&p);
	scanf("%s",arr);
	if(p==arr[1]&&p==arr[4])
	{
			 for(i=0;i<9;i++)
	    {
	    	if(str[i]==arr[0])
	    	break;
		};
	    for(j=0;j<10;j++)
	    {
	    	if(str[j]==arr[3])
	    	break;
		}
		printf("%d %d",i,j);
		if(i>j)
		printf("YES");
		else
		printf("NO");

	}
	else if(p==arr[1]&&p!=arr[4])
	{
	printf("YES");
	}
	else if(p!=arr[1]&&p==arr[4])
	{
		printf("NO");
	}
	else
	{
	    for(i=0;i<9;i++)
	    {
	    	if(str[i]==arr[0])
	    	break;
		};
	    for(j=0;j<10;j++)
	    {
	    	if(str[j]==arr[3])
	    	break;
		}
		printf("%d %d",i,j);
		if(i>j)
		printf("YES");
		else
		printf("NO");
	}

}

#include <stdio.h>
                                                        ///CARD GAME
int main()
{
    char trump ;
    char first_set[5], second_set[5] ;

    scanf("%c", &trump);

    scanf("%s", first_set);
    scanf("%s", second_set);

    if(first_set[1] == trump && second_set[1] != trump)
        printf("YES\n");

    else if(first_set[0] == 'A')
        printf("YES\n");

    else if(first_set[0] == 'k' && second_set[0] != 'A')
        printf("YES\n");

    else if(first_set[0] > second_set[0])
        printf("YES\n");

    else
        printf("NO\n");

    return 0 ;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Wed Dec 28 16:12:33 GMT 2011 *******/

#include <stdio.h>

typedef struct dupla {
	char card;
	int value;
} cell;

cell celula[9];

void start ();
int beats (char c1, char c2);

int main () {
	char trump, c1, c2, s1, s2;
	char string[10];
	scanf ("%c", &trump);
	scanf ("%c", &c1);
	scanf ("%c", &c1);
	scanf ("%c", &s1);
	scanf ("%c", &c2);
	scanf ("%c", &c2);
	scanf ("%c", &s2);

/*	printf ("trunfo: -%c-\ncartas: %c de %c e %c de %c\n", trump, c1, s1, c2, s2);*/

	if (s1 == trump && s2 == trump) {
		if (beats (c1, c2))
			printf ("YES");
		else
			printf ("NO");
	}
	else { /*nao todas sao trunfo*/
		if (s1 == trump) /*primeira eh trunfo*/
			printf ("YES");
		else /*primeira nao eh trunfo*/
			if (s2 == trump) /*segunda eh trunfo*/
				printf ("NO");
			else /*segunda TB nao eh trunfo*/
				if (s1 != s2) /*naipes diferentes*/
					printf ("NO");
				else /*naipes iguais*/
					if (beats (c1, c2))
						printf ("YES");
					else
						printf ("NO");
	}
	return 0;
}

void start () {
	int i;

	celula[0].card = '6';
	celula[1].card = '7';
	celula[2].card = '8';
	celula[3].card = '9';
	celula[4].card = 'T';
	celula[5].card = 'J';
	celula[6].card = 'Q';
	celula[7].card = 'K';
	celula[8].card = 'A';

	for (i = 0; i < 9; i++)
		celula[i].value = i;
}

int beats (char c1, char c2) {
	int i, v1, v2;

	for (i = 0; i < 9; i++) {
		if (celula[i].card == c1)
			v1 = celula[i].value;
		if (celula[i].card == c2)
			v2 = celula[i].value;
	}
	if (v1 > v2) return 1;
	else return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	char a, b, c, d, e;
	a = getchar();
	getchar;
	b = getchar();
	c = getchar();
	getchar();
	d = getchar();
	e = getchar();
	if (c == a)
		printf("YES\n");
	else if (c == e)
		printf("YES\n");
	else
		printf("NO\n");
}

#include <stdio.h>

int tranfCartaParaOrdemDeCarta(char c) {
	switch (c) {
		case 'T': return 1;
		case 'J': return 2;
		case 'Q': return 3;
		case 'K': return 4;
		case 'A': return 5;
		default:
			return EOF;
	}
}

void cardGame() {
	char c, s[2][2];

	scanf("%c", &c);
	scanf("%s %s", s[0], s[1]);

	if (s[0][1] == s[1][1])
		if (tranfCartaParaOrdemDeCarta(s[0][0]) > tranfCartaParaOrdemDeCarta(s[1][0]))
			printf("YES");
		else
			printf("NO");
	else if (s[0][1] == c)
		printf("YES");
	else
		printf("NO");
}

int main() {

	cardGame();
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump[]="SHDC";
    int num[]={6,7,8,9,10,11,12,13,14};
    char trump_in;
    char compare_1[2];
    char compare_2[2];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);
    for(i=0;i<4;i++)
    {
        if(trump[i]==compare_1[1] && trump[i]==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump[i])
                {
                printf("YES");
                return 0;
                }
                else
                {
                        if(compare_1[0]>compare_2[0])
                        {
                        printf("YES");
                        return 0;
                        }
                        else
                        {
                        printf("NO");
                        return 0;
                        }
                }
        }
    }
    return 0;
}
/****** PCCA -Thu Dec 08 14:34:29 GMT 2011 *******/

#include <stdio.h>

int main()
{
    char trump ;
    char first_set[5], second_set[5] ;

    scanf("%c", &trump);

    scanf("%s", first_set);
    scanf("%s", second_set);

    if(first_set[1] == trump)
        printf("YES\n");

    else if(first_set[0] == 'A')
        printf("YES\n");

    else if(first_set[0] == 'k' && second_set[0] != 'A')
        printf("YES\n");

    else if(first_set[0] > second_set[0])
        printf("YES\n");

    else
        printf("NO\n");

    return 0 ;
}

// Code Forces 106A
#include<stdio.h>
int main()
{char trump,C0,C1,B0,B1;int camp1,camp2;
    scanf("%c\n%c%c\n%c%c",&trump,&C0,&C1,&B0,&B1);
    if((C1==trump)&&(B1!=trump)) {printf("YES\n");return 0;}
    if((C1!=trump)&&(B1==trump)) {printf("NO\n");return 0;}
    if(C0=='T') camp1=10;if(C0=='J') camp1=11;if(C0=='Q') camp1=12;if(C0=='K') camp1=13;if(C0=='A') camp1=14;
    if(B0=='T') camp2=10;if(B0=='J') camp2=11;if(B0=='Q') camp2=12;if(B0=='K') camp2=13;if(B0=='A') camp2=14;
    if(camp1>camp2)printf("YES\n");else printf("NO\n");
    return 0;}

#include<stdio.h>
int main()
{
	char strSuit;
	char strCard1[3], strCard2[3];
	scanf("%c",&strSuit);
	scanf("%s %s",strCard1, strCard2);
	if(strCard1[1]==strSuit||strCard1[1]==strCard2[1])
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char trump_in;
    char compare_1[3];
    char compare_2[3];
    int i;
    scanf("%c",&trump_in);
    scanf("%s %s",&compare_1,&compare_2);

    if(compare_1[0]=='T')
    compare_1[0]=10;
    else if(compare_1[0]=='J')
    compare_1[0]=11;
    else if(compare_1[0]=='Q')
    compare_1[0]=12;
    else if(compare_1[0]=='K')
    compare_1[0]=13;
    else if(compare_1[0]=='A')
    compare_1[0]=14;
    else
    compare_1[0] = compare_1[0] - '0';

    if(compare_2[0]=='T')
    compare_2[0]=10;
    else if(compare_2[0]=='J')
    compare_2[0]=11;
    else if(compare_2[0]=='Q')
    compare_2[0]=12;
    else if(compare_2[0]=='K')
    compare_2[0]=13;
    else if(compare_2[0]=='A')
    compare_2[0]=14;
    else
    compare_2[0] = compare_2[0] - '0';

    if(compare_1[1]=='S')
    compare_1[1]=4;
    else if(compare_1[1]=='H')
    compare_1[1]=3;
    else if(compare_1[1]=='D')
    compare_1[1]=2;
    else
    compare_1[1]=1;

    if(compare_2[1]=='S')
    compare_2[1]=4;
    else if(compare_2[1]=='H')
    compare_2[1]=3;
    else if(compare_2[1]=='D')
    compare_2[1]=2;
    else
    compare_2[1]=1;

    if(trump_in=='S')
    trump_in=4;
    else if(trump_in=='H')
    trump_in=3;
    else if(trump_in=='D')
    trump_in=2;
    else
    trump_in=1;

        if(trump_in==compare_1[1] && trump_in==compare_2[1])
            {
                if(compare_1[0]>compare_2[0])
                {
                printf("YES");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
            }
        else
        {
                if(compare_1[1]==trump_in)
                {
                printf("YES");
                return 0;
                }
                else if(compare_2[1]==trump_in)
                {
                printf("NO");
                return 0;
                }
                else
                {
                printf("NO");
                return 0;
                }
        }
    return 0;
}
/****** PCCA -Fri Dec 09 16:39:46 GMT 2011 *******/

#include <stdlib.h>
#include <stdio.h>

int main(){
    char trump[1];
    char first[2],second[2];
    int f,s;

    scanf("%s",trump);
//    printf("%s\n",trump);
    scanf("%s %s",first,second);
//    printf("%s %s\n",first,second);

    if(first[1] == second[1]){
        switch (first[0]){
        case 'A':
            if(second[0] == 'A'){
                printf("NO");
            }else{
                printf("YES");
            }
            break;
        case 'K':
            if(second[0] == 'A' || second[0] == 'K'){
                printf("NO");
            }else{
                printf("YES");
            }
            break;
        case 'Q':
            if(second[0] == 'A' || second[0] == 'K'|| second[0] == 'Q'){
                printf("NO");
            }else{
                printf("YES");
            }
            break;
        case 'J':
            if(second[0] == 'A' || second[0] == 'K' || second[0] == 'Q' || second[0] == 'J'){
                printf("NO");
            }else{
                printf("YES");
            }
            break;
        case 'T':
            if(second[0] == 'A' || second[0] == 'K'|| second[0] == 'Q' || second[0] == 'J' || second[0] == 'T'){
                printf("NO");
            }else{
                printf("YES");
            }
            break;
        default:
            if(second[0] - first[0] >= 0){
                printf("NO");
            }else{
                printf("YES");
            }
            break;
        }

    }else if(first[1] == trump[0]){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

#include <stdio.h>

struct carta {
	int valor;
	char naipe;
};

int main(){
	struct carta primeira;
	struct carta segunda;
	char trunfo, c;
	scanf ("%c", &trunfo);
	scanf ("%c", &c);
	switch (c){
		case '6':
			primeira.valor = 6;
		case '7':
			primeira.valor = 7;
		case '8':
			primeira.valor = 8;
		case '9':
			primeira.valor = 9;
		case 'T':
			primeira.valor = 10;
			break;
		case 'J':
			primeira.valor = 11;
			break;
		case 'Q':
			primeira.valor = 12;
			break;
		case 'K':
			primeira.valor = 13;
			break;
		case 'A':
			primeira.valor = 14;
			break;
	}
	scanf ("%c", &c);
	primeira.naipe = c;
	scanf ("%c", &c);
	switch (c){
		case '6':
			segunda.valor = 6;
		case '7':
			segunda.valor = 7;
		case '8':
			segunda.valor = 8;
		case '9':
			segunda.valor = 9;
		case 'T':
			segunda.valor = 10;
			break;
		case 'J':
			segunda.valor = 11;
			break;
		case 'Q':
			segunda.valor = 12;
			break;
		case 'K':
			segunda.valor = 13;
			break;
		case 'A':
			segunda.valor = 14;
			break;
	}
	scanf ("%c", &c);
	segunda.naipe = c;
	if (segunda.naipe == primeira.naipe){
		if (primeira.valor > segunda.valor)
			printf ("YES");
		else
			printf ("NO");
	}
	else {
		if (primeira.naipe == trunfo)
			printf ("YES");
		else
			printf ("NO");
	}
	return 0;
}

#include <stdio.h>

struct carta {
	int valor;
	char naipe;
};

int main(){
	struct carta primeira;
	struct carta segunda;
	char trunfo, c;
	scanf ("%c", &trunfo);
	scanf ("%c", &c);
	scanf ("%c", &c);
	switch (c){
		case '6':
			primeira.valor = 6;
		case '7':
			primeira.valor = 7;
		case '8':
			primeira.valor = 8;
		case '9':
			primeira.valor = 9;
		case 'T':
			primeira.valor = 10;
			break;
		case 'J':
			primeira.valor = 11;
			break;
		case 'Q':
			primeira.valor = 12;
			break;
		case 'K':
			primeira.valor = 13;
			break;
		case 'A':
			primeira.valor = 14;
			break;
	}
	scanf ("%c", &c);
	primeira.naipe = c;
	scanf ("%c", &c);
	scanf ("%c", &c);
	switch (c){
		case '6':
			segunda.valor = 6;
		case '7':
			segunda.valor = 7;
		case '8':
			segunda.valor = 8;
		case '9':
			segunda.valor = 9;
		case 'T':
			segunda.valor = 10;
			break;
		case 'J':
			segunda.valor = 11;
			break;
		case 'Q':
			segunda.valor = 12;
			break;
		case 'K':
			segunda.valor = 13;
			break;
		case 'A':
			segunda.valor = 14;
			break;
	}
	scanf ("%c", &c);
	segunda.naipe = c;
	if (segunda.naipe == primeira.naipe){
		if (primeira.valor > segunda.valor)
			printf ("YES");
		else
			printf ("NO");
	}
	else {
		if (primeira.naipe == trunfo)
			printf ("YES");
		else
			printf ("NO");
	}
	return 0;
}

#include <stdio.h>

 int value_converter(char temp){
    if(temp=='6'){
        return 6;
    }
    else if(temp=='7'){
        return 7;
    }
    else if(temp=='8'){
        return 8;
    }
    else if(temp=='9'){
        return 9;
    }
    else if(temp=='T'){
        return 10;
    }
    else if(temp=='J'){
        return 11;
    }
    else if(temp=='Q'){
        return 12;
    }
    else if(temp=='K'){
        return 13;
    }
    else if(temp=='A'){
        return 14;
    }
}

 int main()
 {

    char trump, p1, p2 , p3, p4;

    scanf("%c\n", &trump);
    scanf("%c%c %c%c", &p1,&p2,&p3,&p4);

    int integer_value_of_p11 = value_converter(p1);
    int integer_value_of_p21 = value_converter(p3);
    if(trump==p2 && trump==p4 && integer_value_of_p11 > integer_value_of_p21) {
       printf("YES");
   }
   else if(trump==p2 && trump==p4 && integer_value_of_p11 < integer_value_of_p21) {
       printf("NO");
   }
   else if(trump==p2) {
       printf("YES");
   }
   else if(trump==p4) {
       printf("NO");
   }
   else if( integer_value_of_p11 > integer_value_of_p21 ) {
       printf("YES");
   } else if( integer_value_of_p11 < integer_value_of_p21 ) {
       printf("NO");
   }

return 0;
}

#include<stdio.h>
#include<string.h>
void main(){
 char suit,a[3],b[3];
 scanf("%c",&suit);
scanf("%s %s",a,b);
   if(a[1]==suit&&b[1]!=suit)
	   printf("YES\n");
   else if(a[1]!=suit&&b[1]==suit)
	   printf("NO\n");
   else {
	   if(a[0]>b[0])
		   printf("YES\n");
	   else
		   printf("NO\n");
   }
}

// Code Forces 106A
#include<stdio.h>
#define T 10
#define J 11
#define Q 12
#define K 13
#define A 14
int main()
{
    char trump;
    char Arr[2]={'0','0'};
    char Brr[2]={'0','0'};
//  printf("before: %c%c%c%c\n",Arr[0],Arr[1],Brr[0],Brr[1]);
    scanf("%d",&trump);
    scanf("%c",&Arr[0]);
    scanf("%c",&Arr[1]);
    scanf("%c",&Brr[0]);
    scanf("%c",&Brr[1]);
    //printf("after: %c%c%c%c%c\n",trump,Arr[0],Arr[1],Brr[0],Brr[1]);
    if((Arr[1]==trump)&&(Brr[1]!=trump)) {printf("YES\n");return 0;}
    if((Arr[1]!=trump)&&(Brr[1]==trump)) {printf("NO\n");return 0;}
    if(Arr[0]>Brr[0]) printf("YES\n");
    else printf("NO\n");
    return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int main()
{
        char c,a[3],b[3];
        char p[9][1]={'6', '7', '8', '9', 'T', 'J', 'Q', 'K' , 'A'};
        scanf("%c",&c);
        scanf("%s %s",&a,&b);
        if(a[1]==c)
        printf("YES");
        else
        {
                if(a[0]>=b[0])
                printf("YES");
                else
                printf("NO");
        }
        return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int main()
{
        char c,a[3],b[3];
        char p[9][1]={'6', '7', '8', '9', 'T', 'J', 'Q', 'K' , 'A'};
        scanf("%c",&c);
        scanf("%s %s",&a,&b);
        if(a[1]==c && b[1]!=c)
        printf("YES");
        else
        {
                int x=0,y=0;
                for(int i=0;i<9;i++)
                {
                        if(a[0]==p[i][0])
                        x=i;
                        else if(b[0]==p[i][0])
                        y=i;
                }
                if(x>=y)
                printf("YES");
                else
                printf("NO");
        }
        return 0;
}

#include <stdio.h>

int value_converter(char temp) {
    if(temp=='6') {
        return 6;
    } else if(temp=='7') {
        return 7;
    } else if(temp=='8') {
        return 8;
    } else if(temp=='9') {
        return 9;
    } else if(temp=='T') {
        return 10;
    } else if(temp=='J') {
        return 11;
    } else if(temp=='Q') {
        return 12;
    } else if(temp=='K') {
        return 13;
    } else if(temp=='A') {
        return 14;
    }
    else if(temp=='S') {
        return 15;
    }
    else if(temp=='H') {
        return 16;
    }
    else if(temp=='D') {
        return 17;
    }
    else if(temp=='C') {
        return 18;
    }

}

int main() {

    char trump, p1, p2 , p3, p4;

    scanf("%c\n", &trump);
    scanf("%c%c %c%c", &p1,&p2,&p3,&p4);

   // printf("%c %c %c %c\n",p1,p2,p3,p4);
    int integer_value_of_p11 = value_converter(p1);
    int integer_value_of_p21 = value_converter(p3);

    if( p2==p4 ){
        if( integer_value_of_p11 > integer_value_of_p21 ){
            printf("YES");
        }
        else{
            printf("NO\n");
        }
    }
    else if(p1==trump) {
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}

#include <stdio.h>

int f(char c) {
    if (c <= 0x39) {
        return c - 0x36;
    }

    switch (c) {
        case ('T'):
            return 4;
        case ('J'):
            return 5;
        case ('Q'):
            return 6;
        case ('K'):
            return 7;
        case ('A'):
            return 8;
    }

    return -1;
}

int main () {
    char c = 0;
    char s1[3] = {0};
    char s2[3] = {0};

    scanf("%c %s %s", &c, s1, s2);

    if ((s1[1] == c && s2[1] != c)) {
        printf("YES\n");
        return 0;
    }

    if (f(s1[0]) > f(s2[0])) {
        if (s2[1] == s2[1]) {
            printf("YES\n");
            return 0;
        } else if (s2[1] != c) {
            printf("YES\n");
            return 0;
        }
    }

    printf("NO\n");
    return 0;
}

#include<stdio.h>
int s(char c);
int main(){
char a,b,c,d,t;
int i,j;
scanf("%c\n",&t);
scanf("%c%c %c%c",&a,&b,&c,&d);
if(b==t&&d!=t)
    printf("YES\n");
else if(d==t&&b!=t)
    printf(" NO\n");
else{
    i=s(a);
    j=s(c);
    if(i-j>0)
      printf("YES\n");
    else
    printf("NO\n");
}
return 0;
}
int s(char c){
if('5'<c&&c<='9')
    return c-'0';
if(c=='T')
    return 10;
if(c=='J')
    return 11;
if(c=='K')
    return 13;
if(c=='A')
    return 14;
if(c=='Q')
    return 12;
}