There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump. The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.

The first line contains the tramp suit. It is "S", "H", "D" or "C". The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").

Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class A106 {
	public static void main (String args[]){
		Scanner in = new Scanner(System.in);
		char hokm = in.next().charAt(0);
		char[] a = in.next().toCharArray();
		char[] b = in.next().toCharArray();
		Map<Character, Integer> m = new TreeMap<Character, Integer>();
		m.put('6', 6);m.put('7', 7);m.put('8', 8);m.put('9', 9);m.put('T',10);
		m.put('J', 11);m.put('Q', 12);m.put('K', 13);m.put('A', 14);
		if(a[1]==b[1]){
			if(m.get(a[0])>m.get(b[0]))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
		else {
			if(a[1]==hokm)
				System.out.println("YES");
			else if(b[1]==hokm)
				System.out.println("NO");
			else
				System.out.println("NO");
		}
	}
}

import java.util.*;

public class Temp {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String cards="6789TJQKA";
        String coz=in.next();
        char c=coz.charAt(0);
        String s1=in.next(), s2=in.next();
        if (s1.charAt(1)==c && s2.charAt(1)!=c){ System.out.print("YES"); return;}
        if (s1.charAt(1)==s2.charAt(1) && cards.indexOf(s1.charAt(0))>cards.indexOf(s2.charAt(0)))
            System.out.print("YES");
        else
            System.out.print("NO");
    }
}

import java.io.*;
import java.math.*;
import java.util.*;

public class A {

	public static void main(String[] agrs) {
		FastScanner sc = new FastScanner();
//		int yo = sc.nextInt();
//		while(yo-->0) {

//		}

		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();

		List<String> list = new ArrayList<>();
		list.add("6");list.add("7");list.add("8");list.add("9");list.add("T");
		list.add("J");list.add("Q");list.add("K");list.add("A");

		List<String> list2 = new ArrayList<>();
		list2.add("S");list2.add("H");list2.add("D");list2.add("C");

		if(!(s3.charAt(1)+"").equals(s1) && (s2.charAt(1)+"").equals(s1)) {
			System.out.println("YES");

		}
		else if(!(s2.charAt(1)+"").equals(s1) && (s3.charAt(1)+"").equals(s1)) {
			System.out.println("NO");

		}
		else if(!(s3.charAt(1)+"").equals(s2.charAt(1)+"")) {
			System.out.println("NO");

		}
		else {
//System.out.println(list.indexOf(s2.charAt(0)+"") +" "+ list.indexOf(s3.charAt(0)+""));
			if(list.indexOf(s2.charAt(0)+"") > list.indexOf(s3.charAt(0)+"")) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
	}

	static int mod = 1000000007;
	static long pow(int a, int b) {
		if(b == 0) {
			return 1;
		}
		if(b == 1) {
			return a;
		}
		if(b%2 == 0) {
			long ans = pow(a,b/2);
			return ans*ans;
		}
		else {
			long ans = pow(a,(b-1)/2);
			return a * ans * ans;
		}

	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
        public static void main(String[] arg) throws IOException {
int y=0;
String koz=null,str=null;
String mas[]= {"6","7","8","9","T","J","Q","K","A"};
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String c0 = null,c1 = null,c3 = null,c4 = null, otv=null;

        koz=br.readLine();
        str=br.readLine();

        c0=String.valueOf(str.charAt(0));
        c1=String.valueOf(str.charAt(1));
        c3=String.valueOf(str.charAt(3));
        c4=String.valueOf(str.charAt(4));

        int f=0,s=0;

        for (int i=0;i<9;i++)
        {
            if (mas[i].equals(c0))
            {
                f=i;
            }

            if (mas[i].equals(c3))
            {
                s=i;
            }
        }

       // System.out.println(f+" "+s);

        if (c1.equals(c4))
        {
           if (f>s)
           {
               System.out.println("YES");
           }
            else {
                System.out.println("NO");
                }
        }

 else {

            if (koz.equals(c1))
            {
                System.out.println("YES");
            }
             else {
                System.out.println("NO");
                }
 }
    }
}

import java.io.*;
import java.util.*;

public class CardGame {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        String trump = f.readLine();
        StringTokenizer st = new StringTokenizer(f.readLine());
        String c1 = st.nextToken();
        String c2 = st.nextToken();
        if (c1.charAt(1) == c2.charAt(1))
            if (valueOf(c1.charAt(0)) > valueOf(c2.charAt(0)))
                System.out.println("YES");
            else
                System.out.println("NO");
        else
            if (c1.substring(1, 2).equals(trump))
                System.out.println("YES");
            else
                System.out.println("NO");

    }

    public static int valueOf(char c)
    {
        String s = "6789TJQKA";
        return s.indexOf(c);
    }
}

import java.util.HashMap;
import java.util.Scanner;

public class durak {

	static final int rankIndex = 0;
	static final int colorIndex = 1;

	public static void main(String[] args) throws NullPointerException {
		Scanner stdin = new Scanner(System.in);
		String trump = stdin.next();

		String c1 = stdin.next();
		String c2 = stdin.next();

		HashMap<Character, Integer> map = new HashMap<Character, Integer>();
		map.put('6', 0);
		map.put('7', 1);
		map.put('8', 2);
		map.put('9', 3);
		map.put('T', 4);
		map.put('J', 5);
		map.put('Q', 6);
		map.put('K', 7);
		map.put('A', 8);

		if(c1.charAt(colorIndex) == c2.charAt(colorIndex)) {
			if(map.get(c1.charAt(rankIndex)) > map.get(c2.charAt(rankIndex))) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
		else if (c1.charAt(colorIndex) == trump.charAt(0)) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}

		stdin.close();
	}
}

import java.util.Scanner;
public class Card_Game {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char [] ch = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K' ,'A'};
        char trump = sc.nextLine().charAt(0);
        String [] st = sc.nextLine().split(" ");
        String ans = "";
        if(trump == st[0].charAt(1) && st[1].charAt(1) != st[0].charAt(1)){
            ans = "YES";
        }
        else if(st[0].charAt(1) == st[1].charAt(1)){
            if(search(ch,st[0].charAt(0)) > search(ch,st[1].charAt(0)))
                ans = "YES";
            else
                ans = "NO";
        }
        else
            ans = "NO";
        System.out.println(ans);
    }

    public static int search(char [] a, char key){
        for(int i = 0; i< a.length;i++){
            if(a[i] == key )
                return i;
        }
        return -1;
    }

}

import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args) throws Exception
	{
	    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    String str1="6789TJQKA";
	    String s=br.readLine();
	    String ss=br.readLine();
	    String str[]=ss.split(" ");
	    char ar=str[0].charAt(0),at=str[1].charAt(0);
        if(str[0].charAt(1)==str[1].charAt(1)&&str1.indexOf(ar)>str1.indexOf(at))
        {
            System.out.println("YES");
            return;
        }
        if(str[0].charAt(1)!=str[1].charAt(1)&&Character.toString(str[0].charAt(1)).equals(s))
        {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
	}
}

import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
        Reader.init(System.in);
        String trump =Reader.next();
        String t1 =Reader.next();
        String t2 =Reader.next();
        int c=0;
        if(trump.charAt(0)==t1.charAt(1)&&t1.charAt(1)!=t2.charAt(1))
        {
            System.out.println("YES");
            return;
        }
        else
        if(trump.charAt(0)==t2.charAt(1)&&t2.charAt(1)!=t1.charAt(1))
        {
            System.out.println("NO");
            return;
        }
        else
        if(t1.charAt(1)!=t2.charAt(1))
        {
            System.out.println("NO");
            return;
        }
        else
        if(Character.isAlphabetic(t1.charAt(0))&&Character.isAlphabetic(t2.charAt(0)))
        {
        if(t1.charAt(0)=='A'&&(t2.charAt(0)=='K'||t2.charAt(0)=='Q'||t2.charAt(0)=='J'||t2.charAt(0)=='T'))
            c=1;
        else
        if(t1.charAt(0)=='K'&&(t2.charAt(0)=='Q'||t2.charAt(0)=='J'||t2.charAt(0)=='T'))
            c=1;
            else

        if(t1.charAt(0)=='Q'&&(t2.charAt(0)=='J'||t2.charAt(0)=='T'))
            c=1;
        else
        if(t1.charAt(0)=='J'&&(t2.charAt(0)=='T'))
            c=1;

        }
        else
        if(Character.isAlphabetic(t1.charAt(0)))
        {
            System.out.println("YES");
            return;
        }
        else

        if(Character.isAlphabetic(t2.charAt(0)))
        {
            System.out.println("NO");
            return;
        }
        else
            if(Integer.valueOf(t1.charAt(0)+"")>Integer.valueOf(t2.charAt(0)+""))
                c=1;

        System.out.println(c==1?"YES":"NO");

  }
}
class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static public void nextIntArrays(int[]... arrays) throws IOException {
        for (int i = 1; i < arrays.length; ++i) {
            if (arrays[i].length != arrays[0].length) {
                throw new InputMismatchException("Lengths are different");
            }
        }
        for (int i = 0; i < arrays[0].length; ++i) {
            for (int[] array : arrays) {
                array[i] = nextInt();
            }
        }
    }

    static public void nextLineArrays(String[]... arrays) throws IOException {
        for (int i = 1; i < arrays.length; ++i) {
            if (arrays[i].length != arrays[0].length) {
                throw new InputMismatchException("Lengths are different");
            }
        }
        for (int i = 0; i < arrays[0].length; ++i) {
            for (String[] array : arrays) {
                array[i] = reader.readLine();
            }
        }
    }
}

import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		Scanner nm = new Scanner(System.in);
		char karta[] = { '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
		String s = nm.next(), k1 = nm.next(), k2 = nm.next();
		char koz = s.charAt(0), k11 = k1.charAt(0), k12 = k1.charAt(1), k21 = k2
				.charAt(0), k22 = k2.charAt(1);
		int ind_k1=0, ind_k2=0;
		for (int i = 0; i < 9; i++) {
			if (karta[i] == k11) {
				ind_k1 = i;
			}
			if (karta[i] == k21) {
				ind_k2 = i;
			}
		}
		if (k12 == k22 && ind_k1 > ind_k2) {
			System.out.println("YES");
			return;
		}else{
			if (k12==k22 && ind_k1<ind_k2) {
				System.out.println("NO");
				return;
			}
		}
		if (k12 == koz) {
			System.out.println("YES");
			return;
		}
		System.out.println("NO");
	}

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Cardgame {
    public static void main(String[] args) throws IOException {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         String brr[]=br.readLine().trim().split(" ");
        String s=brr[0];
        String t,u;
        char c=s.charAt(0);
        char d,e,f,g;
        int p,q;
        int arr[]=new int[130];
        {
            arr[54]=1;
            arr[55]=2;
            arr[56]=3;
            arr[57]=4;
            d='T';
            p=(int)d;
            arr[p]=5;
            d='J';
            p=(int)d;
            arr[p]=6;
            d='Q';
            p=(int)d;
            arr[p]=7;
            d='K';
            p=(int)d;
            arr[p]=8;
            d='A';
            p=(int)d;
            arr[p]=9;
            }
        brr=br.readLine().trim().split(" ");
           t=brr[0];
           u=brr[1];
           d=t.charAt(1);
           e=u.charAt(1);
           f=t.charAt(0);
           g=u.charAt(0);
           p=(int)f;
           q=(int)g;
           if(d==c&&e!=c)
               System.out.println("YES");
           else if((d!=c&&e!=c)&&(arr[p]>arr[q])&&(d==e))
               System.out.println("YES");
            else if((d==c&&e==c)&&(arr[p]>arr[q]))
                System.out.println("YES");
           else
                System.out.println("NO");
    }
}

import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String zz = "6789TJQKA";
        char trump = s.next().charAt(0);
        String a = s.next(), b = s.next();
        char a1 = a.charAt(0);
        char a2 = a.charAt(1);
        char b1 = b.charAt(0);
        char b2 = b.charAt(1);
        if (a2 == trump && b2 != trump) {
            System.out.println("YES");
        } else if (b2 == trump && a2 != trump) {
            System.out.println("NO");
        } else if (a2 == b2){
            int pa = zz.indexOf(a1);
            int pb = zz.indexOf(b1);
            if (pa - pb >= 0) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } else {
            System.out.println("NO");
        }
    }

}

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Alex
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public int convert(char c) {
        if (c >= '6' && c<= '9') return Character.getNumericValue(c);
        if (c == 'T') return 10;
        if (c == 'J') return 11;
        if (c == 'Q') return 12;
        if (c == 'K') return 13;
        if (c == 'A') return 14;
        return -1;
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        char trump = in.readCharacter();
        char[] first = in.next().toCharArray(), second = in.next().toCharArray();
        int firstrank = convert(first[0]), secondrank = convert(second[0]);
        char firsttype = first[1], secondtype = second[1];
        if (firsttype == trump && secondtype != trump) {
            out.print("YES");
            return;
        }
        if (firsttype == secondtype && firstrank > secondrank) {
            out.print("YES");
            return;
        }
        out.print("NO");
    }
}

class InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}
	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			if (Character.isValidCodePoint(c))
				res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}
	public String next() {
		return readString();
	}
	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}
	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}
	public void close() {
		writer.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Author -
 * User: kansal
 * Date: 8/19/11
 * Time: 8:57 PM
 */
public class TrumpCards {
    public static void main(String[] args) {
        reader = new BufferedReader(new InputStreamReader(System.in));
        char trump = next().charAt(0);
        String first = next(), second = next();
        if (first.charAt(1) == second.charAt(1)) {
            if (card(first.charAt(0)) > card(second.charAt(0))) {
                System.out.println("YES");
            }
            else {
                System.out.println("NO");
            }
        }
        else if (first.charAt(1) == trump) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }

    private static int card(char c) {
        if (c >= '6' && 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 return 14;
    }

    public static BufferedReader reader;

    public static StringTokenizer tokenizer = null;

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    static public int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static public long nextLong() {
        return Long.parseLong(nextToken());
    }

    static public String next() {
        return nextToken();
    }

    static public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

public class Main{
  public static void main(String... args)throws IOException{
        Map<Character, Integer> m = new HashMap<Character, Integer>();
        Scanner input = new Scanner (System.in);
        String in = input.next();
        //System.out.println("After conversion: " + in);

        String card1 = input.next() ;
        String  card2 = input.next();

        m.put('T' , 10);
        m.put('J' , 11);
        m.put('Q' , 12);
        m.put('K' , 13);
        m.put('A' , 14);
        boolean same = card1.charAt(1)==card2.charAt(1);
        char c1 = card1.charAt(1);
        char c2 = card2.charAt(1);
        char a = in.charAt(0);
        if(c1 == a&& c2!=a)
            System.out.println("YES");
        else if(c2 == a&& c1!=a)
            System.out.println("NO");
            else{
        //System.out.println("After conversion: " + c1);
        if(same){
int c;
char charInt=card1.charAt(0);
if(charInt>=48 && charInt<=57){
    //System.out.println("not character");
    c = card1.charAt(0) - '0';
}
else{

     c = m.get(charInt);
}
    //System.out.println(c);

int c3;
char charInt2=card2.charAt(0);
//System.out.println("not character" + charInt);
if(charInt2>=48 && charInt2<=57){

    c3 = card2.charAt(0) - '0';
}
else{
   // System.out.println("Character");
     c3 = m.get(charInt2);
}
            //System.out.println(c3);
    if(c > c3)
        System.out.println("YES");
    else
        System.out.println("NO");
    }

else  System.out.println("NO");
            }

    }
}

import java.util.*;
import java.io.*;

public class Main{

    public static void main(String[] args) throws IOException{
        Reader sc = new Reader();

        char t = sc.next().charAt(0);

        String[] a = sc.next().split(" ");

        List<Character> l = new ArrayList<Character>();
        l.add('6');
        l.add('7');
        l.add('8');
        l.add('9');
        l.add('T');
        l.add('J');
        l.add('Q');
        l.add('K');
        l.add('A');

        if(a[0].charAt(1)==t && a[1].charAt(1)!=t){
            System.out.println("YES");
            return;
        }

        if(a[0].charAt(1)==a[1].charAt(1)){
            if(l.indexOf(a[0].charAt(0))>l.indexOf(a[1].charAt(0))){
            System.out.println("YES");
            return;
            }
        }

        System.out.println("NO");

    }
}

/*Reader class*/
class Reader
{
    BufferedReader br;
    StringTokenizer tk;
    Reader() throws IOException
    {
        br=new BufferedReader(new InputStreamReader(System.in));
        tk=new StringTokenizer("");
    }
    public int nextInt() throws IOException
    {
        while(!tk.hasMoreTokens())
        {
            tk=new StringTokenizer(br.readLine().replaceAll("\r",""));
        }
        return Integer.parseInt(tk.nextToken());
    }
    public Float nextFloat() throws IOException
    {
        while(!tk.hasMoreTokens())
        {
            tk=new StringTokenizer(br.readLine().replaceAll("\r",""));
        }
        return Float.parseFloat(tk.nextToken());
    }
    public String next() throws IOException
    {
        return br.readLine();
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class CardGame {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tokenizer;
	final double EPSILON = 1e-6;
	final int INF = (1 << 31) - 1;
	String suit;
	String firstCard, secondCard;
	Map<Character, Integer> map;

	CardGame() {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));
		map = new HashMap<Character, Integer>();
	}

	public void close() throws IOException {
		out.close();
		in.close();
	}

	public void enter() throws IOException {
		suit = nextToken().trim();
		firstCard = nextToken().trim();
		secondCard = nextToken().trim();
		// out.println(suit + " " + firstCard + " " + secondCard);
		solve();
	}

	boolean canBeat() {
		if (firstCard.charAt(1) == secondCard.charAt(1)
				&& map.get(firstCard.charAt(0)) > map.get(secondCard.charAt(0)))
			return true;

		if ((firstCard.charAt(1) + "").equals(suit) && !(secondCard.charAt(1) + "").equals(suit))
			return true;

		return false;
	}

	public void solve() {
		map.put('6', 6);
		map.put('7', 7);
		map.put('8', 8);
		map.put('9', 9);
		map.put('T', 10);
		map.put('J', 11);
		map.put('Q', 12);
		map.put('K', 13);
		map.put('A', 14);
		if (canBeat())
			out.println("YES");
		else
			out.println("NO");

	}

	public static void main(String[] args) throws IOException {
		CardGame obj = new CardGame();
		obj.enter();
		obj.close();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Created by saksham on 08-08-2016.
 * 106A
 */
public class CardGame {
    public static void main(String []args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char trump = (char) br.read();
        br.readLine();
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        String temp = st.nextToken();
        char[] card1 = temp.toCharArray();
        temp = st.nextToken();
        char[] card2 = temp.toCharArray();
        if(card1[1] == card2[1]) {
            int val1 = 0, val2 = 0;
            if(card1[0] == 'T' || card1[0] == 'J' || card1[0] == 'Q' || card1[0] == 'K' || card1[0] == 'A') {
                if(card1[0] == 'T') val1 = 10;
                else if(card1[0] == 'J') val1 = 11;
                else if(card1[0] == 'Q') val1 = 12;
                else if(card1[0] == 'K') val1 = 13;
                else if(card1[0] == 'A') val1 = 14;
            } else {
                val1 = Character.getNumericValue(card1[0]);
            }
            if(card2[0] == 'T' || card2[0] == 'J' || card2[0] == 'Q' || card2[0] == 'K' || card2[0] == 'A') {
                if(card2[0] == 'T') val2 = 10;
                else if(card2[0] == 'J') val2 = 11;
                else if(card2[0] == 'Q') val2 = 12;
                else if(card2[0] == 'K') val2 = 13;
                else if(card2[0] == 'A') val2 = 14;
            } else {
                val2 = Character.getNumericValue(card2[0]);
            }
            if(val1 > val2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } else if(card1[1] == trump) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

import static java.util.Arrays.deepToString;

import java.io.*;
import java.util.*;

public class B {

    static void solve() throws Exception {
        char trump = next().toCharArray()[0];
        char[] card1 = next().toCharArray();
        switch (card1[0]) {
        case 'T':
            card1[0] = 'A';
            break;
        case 'J':
            card1[0] = 'B';
            break;
        case 'Q':
            card1[0] = 'C';
            break;
        case 'K':
            card1[0] = 'D';
            break;
        case 'A':
            card1[0] = 'E';
            break;
        }
        char[] card2 = next().toCharArray();
        switch (card2[0]) {
        case 'T':
            card2[0] = 'A';
            break;
        case 'J':
            card2[0] = 'B';
            break;
        case 'Q':
            card2[0] = 'C';
            break;
        case 'K':
            card2[0] = 'D';
            break;
        case 'A':
            card2[0] = 'E';
            break;
        }
        if(card1[1] == card2[1]){
            if(card1[0] > card2[0]){
                System.out.print("YES");
            }else{
                System.out.print("NO");
            }
        }else if(card1[1] == trump){
            System.out.print("YES");
        }else{
            System.out.print("NO");
        }
    }

    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    static void debug(Object... a) {
        System.err.println(deepToString(a));
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static void main(String[] args) {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            solve();
            br.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {

	private static BufferedReader input;	// ���� ����� ����� ������ ��������� ������ �� ������-���� ������
	private static PrintWriter output;	// ���� ����� ����� ������ ������ ������
	private static StreamTokenizer stoken;	// ���� ����� ������ ����� ��������� ���������� �������. �� ��������� ����������� - ������

	static String fin = "input";
	static String fout = "output";

	private static void solve() throws IOException{
		String master = input.readLine();
		String temp = input.readLine();
		String[] cards = temp.split(" ");

		if (cards[0].charAt(1)==cards[1].charAt(1)){
			int first = 0, second = 0;
			switch (cards[0].charAt(0)){
				case '6': {first = 6; break;}
				case '7': {first = 7; break;}
				case '8': {first = 8; break;}
				case '9': {first = 9; break;}
				case 'T': {first = 10; break;}
				case 'J': {first = 11; break;}
				case 'Q': {first = 12; break;}
				case 'K': {first = 13;break;}
				case 'A': {first = 14;break;}
			}

			switch (cards[1].charAt(0)){
				case '6': {second = 6;break;}
				case '7': {second = 7;break;}
				case '8': {second = 8;break;}
				case '9': {second = 9;break;}
				case 'T': {second = 10;break;}
				case 'J': {second = 11;break;}
				case 'Q': {second = 12;break;}
				case 'K': {second = 13;break;}
				case 'A': {second = 14;break;}
			}

			if (first>second){
				output.print("YES");
			}else{
				output.print("NO");
			}
		}else{
			if (cards[0].charAt(1)==master.charAt(0)){
				output.print("YES");
			}else{
				output.print("NO");
			}
		}
	}

	public static void main(String[] args) throws IOException {
		//�������� ������
		input = new BufferedReader(new InputStreamReader(System.in));
		output = new PrintWriter(System.out);

		//�������� ������
		//input = new BufferedReader(new FileReader(fin + ".txt"));
		//output = new PrintWriter(new FileWriter(fout + ".txt"));

		stoken = new StreamTokenizer(input);

		//����� �������
		solve();

		//�������� �����
		input.close();
		//����� ������
		output.flush();
		//�������� �����
		output.close();
	}

	//��������� 32-������ ����� �����
	private static int nextInt() throws IOException {
		return (int) nextDouble();
	}

	//��������� 64-������ ����� �����
	private static long nextLong() throws IOException {
		return (long) nextDouble();
	}

	//��������� 64-������ ������� �����
	private static double nextDouble() throws IOException {
		stoken.nextToken();
		return stoken.nval;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Sreesasanka
 */
public class CardGame {
    public static void main(String args[]) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String s1 = br.readLine();
        if(s.charAt(0)==s1.charAt(1)&&s1.charAt(1)!=s1.charAt(4))
        {
            System.out.println("YES");
        }
        else if(s.charAt(0)!=s1.charAt(1)&&s1.charAt(1)!=s1.charAt(4))
        {
            System.out.println("NO");
        }
        else if(Compare(s1.charAt(0),s1.charAt(3)))
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }
    public static boolean Compare(char a,char b)
    {
        int i=0,j=0;
        if(a=='6')
        {
            i=1;
        }
        else if(a=='7')
        {
            i=2;
        }
        else if(a=='8')
        {
            i=3;
        }
        else if(a=='9')
        {
            i=4;
        }
        else if(a=='T')
        {
            i=5;
        }
        else if(a=='J')
        {
            i=6;
        }
        else if(a=='Q')
        {
            i=7;
        }
        else if(a=='K')
        {
            i=8;
        }
        else if(a=='A')
        {
            i=9;
        }
        if(b=='6')
        {
            j=1;
        }
        else if(b=='7')
        {
            j=2;
        }
        else if(b=='8')
        {
            j=3;
        }
        else if(b=='9')
        {
            j=4;
        }
        else if(b=='T')
        {
            j=5;
        }
        else if(b=='J')
        {
            j=6;
        }
        else if(b=='Q')
        {
            j=7;
        }
        else if(b=='K')
        {
            j=8;
        }
        else if(b=='A')
        {
            j=9;
        }
        if(i>=j)
        {
            return true;
        }
        return false;
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws IOException {
		Task task = new Task();
		task.getData();
		task.solve();
		task.printAnswer();
	}
}

class Task {
	char suit;
	String firstCard = "";
	String secondCard = "";

	StringBuilder answer = new StringBuilder();

	public void getData() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		suit = br.readLine().charAt(0);
		String[] cards = br.readLine().split(" ");

		firstCard = cards[0];
		secondCard = cards[1];
	}

	public void solve() {
		char[] rankArray = { '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
		Map<Character, Integer> rank = new HashMap<Character, Integer>();
		for (int i = 0; i < rankArray.length; ++i) {
			rank.put(rankArray[i], i);
		}

		if (firstCard.charAt(1) == suit) {
			if (secondCard.charAt(1) == suit
					&& rank.get(secondCard.charAt(0)) > rank.get(firstCard
							.charAt(0))) {
				answer.append("NO");
			} else {
				answer.append("YES");
			}
			return;
		}
		if (firstCard.charAt(1) == secondCard.charAt(1)
				&& rank.get(firstCard.charAt(0)) > rank.get(secondCard
						.charAt(0))) {
			answer.append("YES");
		} else {
			answer.append("NO");
		}
	}

	public void printAnswer() {
		System.out.print(answer);
	}
}

class Query {
	String type;
	int x;
	int y;

	Query(String type, int x, int y) {
		this.type = type;
		this.x = x;
		this.y = y;
	}
}

class Pair<T> {
	T diameter;
	T color;

	Pair(T color, T diameter) {
		this.diameter = diameter;
		this.color = color;
	}
}

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;

        public void run() {
            char t = sc.next().charAt(0);
            char[] a = sc.next().toCharArray();
            char[] b = sc.next().toCharArray();
            int[] word = new int[256];
            int i = 0;
            word['6'] = i++; word['7'] = i++; word['8'] = i++; word['9'] = i++;
            word['T'] = i++; word['J'] = i++; word['Q'] = i++; word['K'] = i++; word['A'] = i++;
            int win = 0;
            if (a[1] == t) {
                if (b[1] != t) win = 0;
                else if (word[a[0]] > word[b[0]]) win = 0;
                else win = 1;
            }
            else if (a[1] == b[1]) {
                if (word[a[0]] > word[b[0]]) {
                    win = 0;
                }
                else win = 1;
            }
            else {
                win = 1;
            }
            System.out.println(win == 0 ? "YES" : "NO");
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}

import java.util.Scanner;

public class other {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan = new Scanner(System.in);
        String koz = scan.next();
        String str1 = scan.next();
        String str2 = scan.next();

        String arr = "6789TJQKA";

        if(str1.charAt(1) == koz.charAt(0) && str2.charAt(1) != koz.charAt(0)){
            System.out.println("YES");
        }else{

            if(str1.charAt(1)==str2.charAt(1)){
                if(arr.indexOf(str1.charAt(0)) > arr.indexOf(str2.charAt(0))){
                    System.out.println("YES");
                }else
                    System.out.println("NO");
            }
            else
                System.out.println("NO");
        }

    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class solver {
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    final boolean OJ=System.getProperty("ONLINE_JUDGE")!=null;

    String readString() throws IOException{
        while (tok==null || !tok.hasMoreTokens()){
            tok=new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }
    int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(readString());
    }
    long readLong() throws NumberFormatException, IOException{
        return Long.parseLong(readString());
    }
    double readDouble() throws NumberFormatException, IOException{
        return Double.parseDouble(readString());
    }

    void Solve() throws NumberFormatException, IOException{
        char cos=readString().charAt(0);
        int[] karts=new int[255];
        karts['6']=6;
        karts['7']=7;
        karts['8']=8;
        karts['9']=9;
        karts['T']=10;
        karts['J']=11;
        karts['Q']=12;
        karts['K']=13;
        karts['A']=14;
        String f=readString();
        String s=readString();
        if (f.charAt(1)==s.charAt(1)){
            if (karts[f.charAt(0)]>karts[s.charAt(0)]){
                out.println("YES");
            }else{
                out.println("NO");
            }
            return;
        }

        if (f.charAt(1)==cos){
            out.println("YES");
        }else{
            out.println("NO");
        }

    }
    void Run() throws NumberFormatException, IOException{
        if (OJ){
            in =new BufferedReader(new InputStreamReader(System.in));
            out=new PrintWriter(System.out);
        }else{
            in=new BufferedReader(new FileReader("input.txt"));
            out=new PrintWriter("output.txt");
        }

        long h=System.currentTimeMillis();
        Solve();
       // System.err.println(System.currentTimeMillis()-h);
        in.close();
        out.close();
    }
    public static void main(String[] args) throws NumberFormatException, IOException{
        new solver().Run();
    }
}

import java.io.*;
import java.util.*;

public class Main implements Runnable {

	public void _main() throws IOException {
		char trump = next().charAt(0);
		char[] card1 = next().toCharArray();
		char[] card2 = next().toCharArray();
		boolean t1 = card1[1] == trump;
		boolean t2 = card2[1] == trump;
		String res = "NO";
		if (t1 && !t2)
			res = "YES";
		if ((t1 && t2 || card1[1] == card2[1])  && f(card1[0]) > f(card2[0]))
			res = "YES";
		out.println(res);
	}

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

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.UK);
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}

import java.io.*;
import java.util.*;

public class CF {

    public static void main(String[] args) throws IOException {
        //FastScanner in = new FastScanner(new FileInputStream(new File("input.txt")));
        //PrintWriter out = new PrintWriter(new File("output.txt"));
        FastScanner in = new FastScanner(System.in);
        String c = in.next();
        String a = in.next();
        String b = in.next();
        int[] tab = new int[200];
        tab['6'] = 6;
        tab['7'] = 7;
        tab['8'] = 8;
        tab['9'] = 9;
        tab['T'] = 10;
        tab['J'] = 11;
        tab['Q'] = 12;
        tab['K'] = 13;
        tab['A'] = 14;
        tab['J'] = 11;
        tab['Q'] = 12;
        tab['K'] = 13;
        tab['A'] = 14;

        if (a.charAt(1) == c.charAt(0) && a.charAt(1) != b.charAt(1)) {
            System.out.println("YES");
        } else if (a.charAt(1) == b.charAt(1) && tab[a.charAt(0)] > tab[b.charAt(0)]) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

    public static List<int[]> list = new LinkedList<>();

    public static void Permute(int[] input, int startindex) {
        int size = input.length;
        if (size == startindex + 1) {
            int[] tab = new int[size];
            for (int i = 0; i < tab.length; i++) {
                tab[i] = input[i];
            }
            list.add(tab);
        } else {
            for (int i = startindex; i < size; i++) {
                int temp = input[i];
                input[i] = input[startindex];
                input[startindex] = temp;
                Permute(input, startindex + 1);
                int temp2 = input[i];
                input[i] = input[startindex];
                input[startindex] = temp2;
            }
        }
    }

    public static int[] radixSort(int[] f) {
        return radixSort(f, f.length);
    }

    public static int[] radixSort(int[] f, int n) {
        int[] to = new int[n];
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) {
                b[1 + (f[i] & 0xffff)]++;
            }
            for (int i = 1; i <= 65536; i++) {
                b[i] += b[i - 1];
            }
            for (int i = 0; i < n; i++) {
                to[b[f[i] & 0xffff]++] = f[i];
            }
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) {
                b[1 + (f[i] >>> 16)]++;
            }
            for (int i = 1; i <= 65536; i++) {
                b[i] += b[i - 1];
            }
            for (int i = 0; i < n; i++) {
                to[b[f[i] >>> 16]++] = f[i];
            }
            int[] d = f;
            f = to;
            to = d;
        }
        return f;

    }

    private static class FastScanner {

        private final InputStream stream;
        private final byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextArrayInt(int n) {
            int tab[] = new int[n];
            for (int i = 0; i < n; i++) {
                tab[i] = nextInt();
            }
            return tab;
        }

        public String[] nextArrayString(int n) {
            String tab[] = new String[n];
            for (int i = 0; i < n; i++) {
                tab[i] = next();
            }
            return tab;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isEndline(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A_82_CardGame {

    private static String strength = "6789TJQKA";

    public static void main(String[] args) {
        try {
            BufferedReader input = new BufferedReader(new InputStreamReader(
                    System.in));

            String trumpCard = input.readLine();

            String line = input.readLine();
            String[] strs = line.split(" ");
            String firstCard = strs[0];
            String secondCard = strs[1];

            if (firstCard.charAt(1) == secondCard.charAt(1)) {
                if (getPossition(firstCard.charAt(0)) > getPossition(secondCard
                        .charAt(0))) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            } else {
                if (firstCard.charAt(1) == trumpCard.charAt(0)
                        && secondCard.charAt(1) != trumpCard.charAt(0)) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int getPossition(char ch) {
        int poss = 0;
        for (int i = 0; i < strength.length(); i++) {
            if (strength.charAt(i) == ch) {
                poss = i;
                break;
            }
        }
        return poss;
    }

}

import java.util.Scanner;
public class game2 {

public static void main (String args[]){

		Scanner scan =new Scanner(System.in);
		String suit []=new String[4];
		suit[0]="S";
		suit[1]="H";
		suit[2]="D";
		suit[3]="C";
		String rank []={"6", "7", "8", "9", "T", "J", "Q", "K" ,"A"};
		String s=new String();
		String p1=new String();
		int x=0;
		int y=0;
		s=scan.nextLine();
		p1=scan.nextLine();
		if(s.charAt(0)==p1.charAt(1)&&s.charAt(0)!=p1.charAt(4))
		{
			System.out.println("YES");
		}

		else
		{
			if(p1.charAt(4)!=p1.charAt(1))
			{
				System.out.println("NO");
			}
			else
			{
			for(int i=0;i<9;i++)
			{
				if(p1.charAt(0)==rank[i].charAt(0))
				{
					x=i;
				}
				if(p1.charAt(3)==rank[i].charAt(0))
				{
					y=i;
				}

			}
			if(x>y)
				System.out.println("YES");
			else
				System.out.println("NO");
			}
		}

	}

}

import java.util.ArrayList;
import java.util.Scanner;

public class Young {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String tramp = sc.next();
		String card1 = sc.next();
		String card2 = sc.next();
		ArrayList<Character> list = new ArrayList<Character>();
		list.add('6');
		list.add('7');
		list.add('8');
		list.add('9');
		list.add('T');
		list.add('J');
		list.add('Q');
		list.add('K');
		list.add('A');
		String res = "NO";

			int index1 = list.indexOf(card1.charAt(0));
			int index2 = list.indexOf(card2.charAt(0));

		if(((card1.charAt(1) == card2.charAt(1) && card1.charAt(0) == tramp.charAt(0) )))
		{
			if( index1 > index2)
			res = "YES";
		}
		else if(card1.charAt(1) == card2.charAt(1) && card1.charAt(0) != tramp.charAt(0) )
		{
			if( index1 > index2)
				res = "YES";
		}
		else if(card1.contains(tramp) && !card2.contains(tramp))
		{
			res  = "YES";
		}

		System.out.println(res);
	}
}

import java.util.HashMap;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        char trump=sc.next().charAt(0);
        String fir=sc.next();
        String sec=sc.next();
        HashMap<Character, Integer> map=new HashMap<Character, Integer>();
        map.put('6', 1);
        map.put('7', 2);
        map.put('8', 3);
        map.put('9', 4);
        map.put('T', 5);
        map.put('J', 6);
        map.put('Q', 7);
        map.put('K', 8);
        map.put('A', 9);
        //System.out.println(fir+" "+sec+" "+trump);
        if(fir.charAt(1)==sec.charAt(1)) {
            if(map.get(fir.charAt(0))>map.get(sec.charAt(0))) System.out.println("YES");
            else System.out.println("NO");
        }else {
            if(fir.charAt(1)==trump) System.out.println("YES");
            else System.out.println("NO");
        }
    }
}

import java.io.*;
import java.util.*;
import java.applet.Applet;
import java.math.BigInteger;

public class Main{
      static PrintWriter out;

    public static void main(String args[]) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        char koz = in.readLine().trim().charAt(0);
        char[] s= in.readLine().toCharArray();
        int[] v = new int[250];
        v['6']=6;
        v['7']=7;
        v['8']=8;
        v['9']=9;
        v['T']=10;
        v['J']=11;
        v['Q']=12;
        v['K']=13;
        v['A']=14;
        if(s[1]==koz && s[4]!=koz ||
                s[1]==koz && s[4]==koz && v[s[0]]>v[s[3]] ||
                s[1]!=koz&&s[4]!=koz&&v[s[0]]>v[s[3]] && s[1]==s[4]){
            out.print("YES");

        }
        else out.print("NO");

        out.close();
     }
  }

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static int value(char c) {
        if (c == 'A') {
            return 14;
        } else if (c == 'K') {
            return 13;
        } else if (c == 'Q') {
            return 12;
        } else if (c == 'J') {
            return 11;
        } else if (c == 'T') {
            return 10;
        } else {
            return Integer.parseInt(Character.toString(c));
        }
    }

    private void solve() throws IOException {
        String trump = nextToken(), first = nextToken(), second = nextToken();
        if (first.charAt(1) == trump.charAt(0) && second.charAt(1) == trump.charAt(0) || first.charAt(1) == second.charAt(1)) {
            if (value(second.charAt(0)) >= value(first.charAt(0))) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        } else if (first.charAt(1) != trump.charAt(0) && second.charAt(1) == trump.charAt(0)) {
            System.out.println("NO");
        } else if (first.charAt(1) == trump.charAt(0) && second.charAt(1) != trump.charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    public static void main(String[] args) {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            new Main().solve();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(239);
        }
    }
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    static String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Eslam Ashraf
 */
public class C82 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        char trump = in.nextLine().trim().charAt(0);

        String [] split = in.nextLine().trim().split(" +");

        String f = split[0];
        String s = split[1];

        if(f.charAt(1)==trump && s.charAt(1)!=trump)System.out.println("YES");
        else if(f.charAt(1)==s.charAt(1) && isGreater(f.charAt(0), s.charAt(0)))System.out.println("YES");
        else System.out.println("NO");
    }

    public static boolean isGreater(char f , char s){
        char [] a = new char []{'6','7','8','9','T','J','Q','K','A'};

        for(int i =0 ; i < a.length ;i++){
            if(a[i]==f)return false;
            if(a[i]==s)return true;
        }

        return false;
    }
}

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String qq = sc.next();
		String f_card = sc.next();
		String s_card = sc.next();
		Map<Character, Integer> mp = new HashMap<Character, Integer>();
		mp.put('6', 6);
		mp.put('7', 7);
		mp.put('8', 8);
		mp.put('9', 9);
		mp.put('T', 10);
		mp.put('J', 11);
		mp.put('Q', 12);
		mp.put('K', 13);
		mp.put('A', 14);
		if (s_card.charAt(1) == f_card.charAt(1) && mp.get(s_card.charAt(0)) < mp.get(f_card.charAt(0))){
			System.out.println("YES");
			return;
		}
		if (f_card.charAt(1) == qq.charAt(0) && f_card.charAt(1) != s_card.charAt(1)){
			System.out.println("YES");
			return;
		}
		System.out.println("NO");
	}
}
/*
 H
 TS 9S
 */

import java.util.Scanner;
import java.util.List;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.TreeSet;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.PrintWriter;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
         String c = sc.next();
         String a = sc.next(),b=sc.next();
         String seq ="6789TJQKA";
         if(a.charAt(1)==b.charAt(1) && seq.indexOf(a.charAt(0))>seq.indexOf(b.charAt(0)) || a.charAt(1)==c.charAt(0) && b.charAt(1)!=c.charAt(0))
              out.println("YES");
         else
            out.println("NO");
        out.flush();
    }
}

import java.util.Scanner;

public class aa {
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String yes = "6789TJQKA";
    String s = sc.next();
    String fi = sc.next();
    String sec = sc.next();
    if(fi.charAt(1)==sec.charAt(1) && yes.indexOf(fi.charAt(0)+"")>yes.indexOf(sec.charAt(0)+"") ||
            (fi.charAt(1)==s.charAt(0)&& sec.charAt(1)!=s.charAt(0)))System.out.println("YES");else
                System.out.println("NO");
}
}

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.io.*;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		// Scanner read = new Scanner(new FileInputStream(new
		// File("input.txt")));
		// PrintWriter out = new PrintWriter(new File("output.txt"));

		Scanner read = new Scanner(System.in);
		String trump = read.next();
		read.nextLine();
		String[] card = read.nextLine().split(" ");
		String x = "6789TJQKA";
//		String[] y = "S H D C".split(" ");
		ArrayList<String> T = new ArrayList<String>();
		ArrayList<Character> rank = new ArrayList<Character>();
		for (int i = 0; i < x.length(); i++)
			rank.add(x.charAt(i));
//		for (int i = 0; i < y.length; i++)
//			T.add(y[i]);
		if (card[0].charAt(1) == trump.charAt(0) && card[1].charAt(1) != trump.charAt(0))
			System.out.println("YES");
		else if (card[0].charAt(1) == card[1].charAt(1)
				&& rank.indexOf(card[0].charAt(0)) > rank.indexOf(card[1].charAt(0))) {
			System.out.println("YES");
		} else
			System.out.println("NO");

	}

}

import java.util.*;
// warm-up
public class CardGame {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String rank = "6789TJQKA";
		char Trump = sc.next().charAt(0); // "Special" character with caps T
		boolean ok = false;
		char[] f = sc.next().toCharArray();
		char[] s = sc.next().toCharArray();
		if((f[1]==s[1] && rank.indexOf(f[0])>rank.indexOf(s[0]))||(f[1]==Trump && s[1]!=Trump)) ok = true;
		System.out.println(ok ? "YES" : "NO");
		sc.close();
	}

	public static void main(String args[]) {
		solve();
	}

}

import java.util.*;

public class A106 {
	private Scanner	input = new Scanner(System.in);
	private String ss = new String("6789TJQKA");
	public static void main(String[] args) {
		A106 okok = new A106();
		okok.solve();
	}
	public void solve() {
		String w = new String();
		String s1 = new String();
		String s2 = new String();
		w = input.next();
		s1 = input.next();
		s2 = input.next();
		int ok = 1;
		if (w.charAt(0) == s1.charAt(1)) {
			if (w.charAt(0) == s2.charAt(1) && biger(s2.charAt(0), s1.charAt(0)) == true) {
				ok = 0;
			}
		} else {
			if(s2.charAt(1)!=s1.charAt(1))ok=0;
			else{
				if(biger(s2.charAt(0),s1.charAt(0))==true)ok=0;
			}
		}
		if(ok==1)System.out.println("YES");
		else System.out.println("NO");
	}
	private boolean biger(char a, char b) {
		int aa = 0, bb = 0;
		while (ss.charAt(aa) != a)aa++;
		while (ss.charAt(bb) != b)bb++;
		return aa > bb;
	}
}

import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String trump = scan.nextLine();
    String l = scan.nextLine();
    char c1rank = l.charAt(0);
    char c1suit = l.charAt(1);
    char c2rank = l.charAt(3);
    char c2suit = l.charAt(4);
    if (c1suit == trump.charAt(0) && c2suit != trump.charAt(0))
      System.out.println("YES");
    else if (c2suit != c1suit)
      System.out.println("NO");
    else if (c1rank == 'A' && c2rank != 'A')
      System.out.println("YES");
    else if (c1rank == 'K' && c2rank !='A' && c2rank != 'K')
      System.out.println("YES");
    else if (c1rank == 'Q' && c2rank != 'A' && c2rank != 'K' && c2rank !='Q')
      System.out.println("YES");
    else if (c1rank == 'J' && c2rank != 'A' && c2rank != 'K' && c2rank != 'Q' && c2rank != 'J')
      System.out.println("YES");
    else if (c1rank == 'T' && c2rank - '9' <= 0 && c2rank - '6' >= 0)
      System.out.println("YES");
    else if (c1rank > c2rank && c1rank - '9' <= 0 && c1rank - '6' >= 0 && c2rank - '9' <= 0 && c2rank - '6' >= 0)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
}

/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);

	char t = sc.next().charAt(0);
	sc.nextLine();
	String str=sc.nextLine();
	String rank="6"+"7"+"8"+"9"+"T"+"J"+"Q"+"K"+"A";
	char c1=str.charAt(0);
	char s1=str.charAt(1);
	char c2=str.charAt(3);
	char s2=str.charAt(4);

	if(s1==s2)
	{

	    if(rank.indexOf(c1)>rank.indexOf(c2))
	    System.out.println("YES");
	    else
	    System.out.println("NO");

	}
	else if(t==s1)
	{
	    System.out.println("YES");
	}
	else
	{
	    System.out.println("NO");
	}
	    sc.close();

	}
}

import java.util.HashMap;
import java.util.Scanner;

public class durak {

	static final int rankIndex = 0;
	static final int colorIndex = 1;

	public static void main(String[] args) throws NullPointerException {
		Scanner stdin = new Scanner(System.in);
		String trump = stdin.next();

		String c1 = stdin.next();
		String c2 = stdin.next();

		HashMap<Character, Integer> map = new HashMap<Character, Integer>();
		map.put('6', 0);
		map.put('7', 1);
		map.put('8', 2);
		map.put('9', 3);
		map.put('T', 4);
		map.put('J', 5);
		map.put('Q', 6);
		map.put('K', 7);
		map.put('A', 8);

		if(c1.charAt(colorIndex) == c2.charAt(colorIndex)) {
			if(map.get(c1.charAt(rankIndex)) > map.get(c2.charAt(rankIndex))) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
		else if (c1.charAt(colorIndex) == trump.charAt(0)) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}

		stdin.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();

        char tr = sc.next().charAt(0);
        String f = sc.next();
        String s = sc.next();

        String order = "6789TJQKA";
        String order2 = "123456789";
        int firstW = 0 , secondW = 0;
        for (int i = 0 ; i < order.length() ; ++ i) {
            if (f.charAt(0) == order.charAt(i)) {
                firstW = (int)order2.charAt(i);
            }
            if (s.charAt(0) == order.charAt(i)) {
                secondW = (int)order2.charAt(i);
            }
        }
        if (f.charAt(1) == s.charAt(1)) {
            if (firstW > secondW) {
                System.out.println("YES");
            }
            else {
                System.out.println("NO");
            }
        }
        else {
            if (f.charAt(1) == tr && s.charAt(1) != tr) {
                System.out.println("YES");
            }
            else {
                System.out.println("NO");
            }
        }

        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author invisible
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CardGame solver = new CardGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class CardGame {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            char c = in.readLine().charAt(0);
            String s[] = in.readLine().split(" ");

            int a[] = new int[200];// "6", "7", "8", "9", "T", "J", "Q", "K" and "A"
            a['6'] = 1;
            a['7'] = 2;
            a['8'] = 3;
            a['9'] = 4;
            a['T'] = 5;
            a['J'] = 6;
            a['Q'] = 7;
            a['K'] = 8;
            a['A'] = 9;

            if (s[0].charAt(1) == s[1].charAt(1))
                out.printLine(a[s[0].charAt(0)] > a[s[1].charAt(0)] ? "YES" : "NO");
            else {
                out.printLine(s[0].charAt(1) == c ? "YES" : "NO");
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();

        char tr = sc.next().charAt(0);
        String f = sc.next();
        String s = sc.next();

        String order = "6789TJQKA";
        int firstW = 0 , secondW = 0;
        for (int i = 0 ; i < order.length() ; ++ i) {
            if (f.charAt(0) == order.charAt(i)) {
                firstW = i;
            }
            if (s.charAt(0) == order.charAt(i)) {
                secondW = i;
            }
        }
        if (f.charAt(1) == s.charAt(1)) {
            if (firstW > secondW) {
                System.out.println("YES");
            }
            else {

                System.out.println("NO");
            }
        }
        else {
            if (f.charAt(1) == tr && s.charAt(1) != tr) {
                System.out.println("YES");
            }
            else {
                System.out.println("NO");
            }
        }

        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

import java.io.*;
import java.util.*;

public class CardGame {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        String trump = f.readLine();
        StringTokenizer st = new StringTokenizer(f.readLine());
        String c1 = st.nextToken();
        String c2 = st.nextToken();
        if (c1.charAt(1) == c2.charAt(1))
            if (valueOf(c1.charAt(0)) > valueOf(c2.charAt(0)))
                System.out.println("YES");
            else
                System.out.println("NO");
        else
            if (c1.substring(1, 2).equals(trump))
                System.out.println("YES");
            else
                System.out.println("NO");

    }

    public static int valueOf(char c)
    {
        String s = "6789TJQKA";
        return s.indexOf(c);
    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
       int first=0,second=0;
        String wrong = input.next();
        String First = input.next();
        String Second = input.next();
        if(First.charAt(0)=='T')
            first=10;
        else if(First.charAt(0)=='J')
            first=11;
        else if(First.charAt(0)=='Q')
            first=12;
        else if(First.charAt(0)=='K')
            first=13;
        else if(First.charAt(0)=='A')
            first=14;
        else
            first=First.charAt(0)-'0';
        if(Second.charAt(0)=='T')
            second=10;
        else if(Second.charAt(0)=='J')
            second=11;
        else if(Second.charAt(0)=='Q')
            second=12;
        else if(Second.charAt(0)=='K')
            second=13;
        else if(Second.charAt(0)=='A')
            second=14;
            else
            second=Second.charAt(0)-'0';
       if(First.charAt(1)==wrong.charAt(0) &&(Second.charAt(1)!=wrong.charAt(0)))
            System.out.println("YES");
       else if(First.charAt(1)==Second.charAt(1)&&first>second)
            System.out.println("YES");
       else System.out.println("NO");
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {

    public static void main(String[] args) throws IOException {
         BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
         String T,f,s;
         StringTokenizer x;
         String c="6789TJQKA";
         do {
            T=in.readLine();
             x=new StringTokenizer(in.readLine());
             f=x.nextToken();
             s=x.nextToken();
             if(f.charAt(1)==s.charAt(1)){
                 if(c.indexOf(f.charAt(0))>c.indexOf(s.charAt(0)))
                     System.out.println("YES");
                 else
                     System.out.println("NO");
             }
             else if(f.charAt(1)==T.charAt(0)){

                 System.out.println("YES");
             }
             else
                 System.out.println("NO");
        } while (in.ready());
    }
}

import java.io.*;
import java.util.*;

// Main class to hold program logic

public class Main {

	public static void main(String[] args) throws IOException {
		// assuming rectangle is parallel to coordinate axes
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String t = br.readLine();
		String s = "6789TJQKA";
		String c[] = br.readLine().split(" ");
		if(c[0].contains(t)&& !c[1].contains(t)){
			System.out.println("YES");
		}
		else if(!c[0].contains(t)&& c[1].contains(t)){
			System.out.println("NO");
		}
		else{
			char o = c[0].charAt(0);
			char n = c[1].charAt(0);
			if(s.indexOf(o)>s.indexOf(n) && c[0].charAt(1)==c[1].charAt(1))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
		// end of main
	}

}

import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class A1008 {
    public static void main(String [] args) /*throws Exception*/ {
        InputStream inputReader = System.in;
        OutputStream outputReader = System.out;
        InputReader in = new InputReader(inputReader);//new InputReader(new FileInputStream(new File("input.txt")));new InputReader(inputReader);
        PrintWriter out = new PrintWriter(outputReader);//new PrintWriter(new FileOutputStream(new File("output.txt")));
        Algorithm solver = new Algorithm();
        solver.solve(in, out);
        out.close();
    }
}

class Algorithm {
    void solve(InputReader ir, PrintWriter pw) {

        char tramp = ir.next().charAt(0);
        String first = ir.next(), second = ir.next();
        char [] symbols = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
        int fValue = 0, sValue = 0;
        char fSuit = first.charAt(1), sSuit = second.charAt(1);

        for (int i = 0; i < 9; i++)
        {
            if (first.charAt(0) == symbols[i]) fValue = i;
            if (second.charAt(0) == symbols[i]) sValue = i;
        }

        if (fValue >= sValue)
        {
            if (fSuit == sSuit || fSuit == tramp)
            {
                pw.print("YES");
                return;
            }
        }
        else
        {
            if (fSuit == tramp && fSuit != sSuit)
            {
                pw.print("YES");
                return;
            }
        }

        pw.print("NO");

    }

    private static void mergeSort(int[] array) {
        if(array.length == 1)
            return;
        int[] first = new int[array.length / 2];
        int[] second = new int[array.length - first.length];
        System.arraycopy(array, 0, first, 0, first.length);
        System.arraycopy(array, first.length, second, 0, second.length);

        mergeSort(first);
        mergeSort(second);

        merge(first, second, array);
    }

    private static void merge(int[] first, int[] second, int[] result) {
        int iFirst = 0;
        int iSecond = 0;
        int j = 0;

        while (iFirst < first.length && iSecond < second.length) {
            if (first[iFirst] < second[iSecond]) {
                result[j] = first[iFirst];
                iFirst++;
            }
            else {
                result[j] = second[iSecond];
                iSecond++;
            }
            j++;
        }
        System.arraycopy(first, iFirst, result, j, first.length - iFirst);
        System.arraycopy(second, iSecond, result, j, second.length - iSecond);
    }

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    String nextLine(){
        String fullLine;
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                fullLine = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return fullLine;
        }
        return null;
    }

    String [] toArray() {
        return nextLine().split(" ");
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
    double nextDouble() {
        return Double.parseDouble(next());
    }
    long nextLong() {
        return Long.parseLong(next());
    }

}

import java.util.Scanner;

public class A106 {
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		String stroka = in.nextLine(), k1 = in.next(), k2 = in.next();

		char s = stroka.charAt(0);

		if (s == k1.charAt(1) && s != k2.charAt(1)) {
			System.out.println("YES");
			return;
		}

		if (k1.charAt(1) != k2.charAt(1)) {
			System.out.println("NO");
			return;
		}

		char q = k1.charAt(0), w = k2.charAt(0);

		int q1, w1;

		if (q == 'T')
			q1 = 10;
		else if (q == 'J')
			q1 = 11;
		else if (q == 'Q')
			q1 = 12;
		else if (q == 'K')
			q1 = 13;
		else if (q == 'A')
			q1 = 14;
		else
			q1 = Integer.parseInt(k1.substring(0, 1));

		if (w == 'T')
			w1 = 10;
		else if (w == 'J')
			w1 = 11;
		else if (w == 'Q')
			w1 = 12;
		else if (w == 'K')
			w1 = 13;
		else if (w == 'A')
			w1 = 14;
		else
			w1 = Integer.parseInt(k2.substring(0, 1));

		if (q1 > w1)
			System.out.println("YES");
		else
			System.out.println("NO");

	}
}

import java.util.Scanner;

/**
 * Created by vinayr on 8/25/17.
 */
public class TrumpCard {
    public static void main(String[] args){
        String s1;
        Scanner sc = new Scanner(System.in);
        s1=sc.next();
        String s2="";
        String s3;
        s2=sc.next();
        s3=sc.next();
        //System.out.println(s1 + " "+s2+ " "+s3);

        String res="6789TJQKA";
        if(s2.charAt(1)==s1.charAt(0) && s3.charAt(1)!=s1.charAt(0))
        {
            System.out.println("YES");

        }
        else if(s2.charAt(1)==s3.charAt(1)){
            if(res.indexOf(s2.substring(0,1)) > res.indexOf(s3.substring(0,1))){
                System.out.println("YES");

            }
            else
                System.out.println("NO");
        }
        else
            System.out.println("NO");

    }
}

import java.util.Scanner;

public class Problem106A {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        scanner.useDelimiter(System.lineSeparator());
        String trumpSuit = scanner.next();
        String[] cards = scanner.next().split(" ");
        scanner.close();
        String firstCard = cards[0];
        String secondCard = cards[1];
        if (firstCard.contains(trumpSuit) && secondCard.contains(trumpSuit)) {
            if (getRank(firstCard.split("")[0]) <= getRank(secondCard.split("")[0])) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        } else if (firstCard.contains(trumpSuit)) {
            System.out.println("YES");
        } else if (secondCard.contains(trumpSuit)) {
            System.out.println("NO");
        } else if (firstCard.split("")[1].equals(secondCard.split("")[1])) {
            if (getRank(firstCard.split("")[0]) <= getRank(secondCard.split("")[0])) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        } else {
            System.out.println("NO");
        }
    }

    private static int getRank(String strRank) {
        switch (strRank) {
            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 14;
            default:
                return 15;
        }
    }
}

import java.util.*;
public class Main {

    private boolean isTrump(String trump, char card){
        if(trump.equals(Character.toString(card))){
            return true;
        }
        else{
            return false;
        }
    }

    public void doIt(){
        Scanner sc = new Scanner(System.in);
        String trump = sc.next();
        String player = sc.next();
        String another = sc.next();
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        for(int i=6; i <= 9; i++){
            map.put(""+ i, i);
        }
        map.put("T", 10);
        map.put("J", 11);
        map.put("Q", 12);
        map.put("K", 13);
        map.put("A", 14);
        char pMark = player.charAt(1);
        int pRank = map.get(Character.toString(player.charAt(0)));
        char aMark = another.charAt(1);
        int aRank = map.get(Character.toString(another.charAt(0)));
        if(aMark == pMark) {
            if(pRank > aRank){
                System.out.println("YES");
            }
            else
                System.out.println("NO");
        }
        else if(isTrump(trump, pMark) && !(isTrump(trump, aMark))){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
    public static void main(String[] args) {
        Main obj = new Main();
        obj.doIt();
    }

}

	import java.util.*;
	public class A {
		public static int f(char yed) {
			if (yed=='T') return 10; else
				if (yed=='J') return 11; else
					if (yed=='Q') return 12; else
						if (yed=='K') return 13; else
							if (yed=='A') return 14;
			 return (int)yed - '0';
		}
	public static void main(String args[]){
    Scanner in = new Scanner(System.in);
String koz=in.next();
String a=in.next(),b=in.next();
if (a.charAt(1) == koz.charAt(0) && b.charAt(1)!=koz.charAt(0)) System.out.println("YES"); else
if (a.charAt(1) == koz.charAt(0) && b.charAt(1)==koz.charAt(0) &&  f(a.charAt(0))>f(b.charAt(0))) System.out.println("YES"); else
if (a.charAt(1) == b.charAt(1) && f(a.charAt(0)) > f(b.charAt(0))) System.out.println("YES"); else
	System.out.println("NO");

	    	}
		}

import java.util.Scanner;
import java.util.HashMap;
public class Solution {
    public static void main(String args[]) {
        Scanner s=new Scanner(System.in);
        char trumpCard=s.next().charAt(0);
        String firstCard=s.next();
        String secondCard=s.next();
        System.out.println(isBeating(firstCard,secondCard,trumpCard));
    }
    public static String isBeating(String firstCard,String secondCard,char trumpCard)
    {
        char firstCardSuit=firstCard.charAt(1);
        char secondCardSuit=secondCard.charAt(1);
        char firstCardRank=firstCard.charAt(0);
        char secondCardRank=secondCard.charAt(0);
        if(firstCardSuit==trumpCard && secondCardSuit!=trumpCard)
        {
            return "YES";
        }
        else if(secondCardSuit==trumpCard && firstCardSuit!=trumpCard)
        {
            return "NO";
        }
        else if(firstCardSuit!=secondCardSuit)
        {
            return "NO";
        }
        else if(rank(firstCardRank)>rank(secondCardRank)){
            return "YES";
        }
        else{
            return "NO";
        }
    }
    public static int rank(char ch)
    {
        HashMap<Character,Integer> hash=new HashMap<>();
        hash.put('6',1);
        hash.put('7',2);
        hash.put('8',3);
        hash.put('9',4);
        hash.put('T',5);
        hash.put('J',6);
        hash.put('Q',7);
        hash.put('K',8);
        hash.put('A',9);
        return hash.get(ch);
    }
}

import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.*;

public class A {

	MyScanner in;
	PrintWriter out;

	public static void main(String[] args) throws Exception {
		new A().run();
	}

	public void run() throws Exception {
		in = new MyScanner();
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	public void solve() throws Exception {
		char c = in.next().charAt(0);
		char[] d = (in.next() + " " + in.next()).toCharArray();

		if ((d[1] == c) ^ (d[4] == c)) {
			if (d[1] == c) {
				out.println("YES");
			} else {
				out.println("NO");
			}
		} else {
			int first = num(d[0]);
			int second = num(d[3]);
			if ((d[1] == d[4]) && (first > second)) {
				out.println("YES");
			} else {
				out.println("NO");
			}
		}

	}

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

	class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() throws Exception {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws Exception {
			while ((st == null) || (!st.hasMoreTokens())) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}

		double nextDouble() throws Exception {
			return Double.parseDouble(next());
		}

		boolean nextBoolean() throws Exception {
			return Boolean.parseBoolean(next());
		}

		long nextLong() throws Exception {
			return Long.parseLong(next());
		}
	}

}

import java.io.*;
import java.util.*;
public class card
{
    public static void main(String[] args)throws IOException
    {

    Scanner sc=new Scanner(System.in);
    String x=sc.next();
    String p=sc.next();
    String q=sc.next();
    String a[]={"6","7","8","9","T","J","Q","K","A"};
    if(p.substring(1,2).compareTo(x)==0&&q.substring(1,2).compareTo(x)!=0)
    {
        System.out.print("YES");
        return;
}
 else if(q.substring(1,2).compareTo(x)==0&&p.substring(1,2).compareTo(x)!=0)
    {
        System.out.print("NO");
        return;
}
else if((q.substring(1,2).compareTo(p.substring(1,2)))==0)
{
    int po=0,po1=0;
    for(int i=0;i<9;i++)
    {
        if(a[i].compareTo(p.substring(0,1))==0)
        po=i;
        if(a[i].compareTo(q.substring(0,1))==0)
        po1=i;
    }
    //System.out.println(po+" "+po1);
    if(po>po1)
    {
        System.out.print("YES");
        return;
    }
else
{
    System.out.print("NO");
    return;
}
}
else
{
     System.out.print("NO");
    return;
}
}
}

import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		int k = 0, k2 = 0;
		if (s2.charAt(0) == 'T')
			k = 10;
		if (s2.charAt(0) == 'J')
			k = 11;
		if (s2.charAt(0) == 'Q')
			k = 12;
		if (s2.charAt(0) == 'K')
			k = 13;
		if (s2.charAt(0) == 'A')
			k = 14;
		if (s3.charAt(0) == 'T')
			k2 = 10;
		if (s3.charAt(0) == 'J')
			k2 = 11;
		if (s3.charAt(0) == 'Q')
			k2 = 12;
		if (s3.charAt(0) == 'K')
			k2 = 13;
		if (s3.charAt(0) == 'A')
			k2 = 14;
		if (k == 0)
			k = (int) s2.charAt(0) - 48;
		if (k2 == 0)
			k2 = (int) s3.charAt(0) - 48;
		if (s2.charAt(1) == s.charAt(0)) {
			if (s2.charAt(1) != s3.charAt(1)) {
				System.out.println("YES");
			}
			if (s2.charAt(1) == s3.charAt(1) && k > k2) {
				System.out.println("YES");
			}
			if (s2.charAt(1) == s3.charAt(1) && k < k2) {
				System.out.println("NO");
			}
		} else if (s2.charAt(1) == s3.charAt(1) && k > k2) {
			System.out.println("YES");
		} else
			System.out.println("NO");
	}
}

import java.io.*;
import java.util.*;

public class Main
{
	public static void main (String[]args)
	{
		Scanner read = new Scanner (new BufferedInputStream (System.in));

		String trump =read.next();

		char[] first = read.next().toCharArray();
		char[] second = read.next().toCharArray();

		int flag=0;

		if ((int)first[1]==(int)trump.charAt(0)&&((int)second[1]!=(int)trump.charAt(0)))
			flag=1;
		else if ((int)first[1]!=(int)trump.charAt(0)&&((int)second[1]==(int)trump.charAt(0)))
			flag=0;
		else
		{
			int a=0;
			int b=0;

			if ((int)first[0]==54)
				a=6;
			else if((int)first[0]==55)
				a=7;
			else if ((int)first[0]==56)
				a=8;
			else if ((int)first[0]==57)
				a=9;
			else if ((int)first[0]==84)
				a=10;
			else if ((int)first[0]==74)
				a=11;
			else if ((int)first[0]==81)
				a=12;
			else if ((int)first[0]==75)
				a=13;
			else if ((int)first[0]==65)
				a=14;

			if ((int)second[0]==54)
				b=6;
			else if((int)second[0]==55)
				b=7;
			else if ((int)second[0]==56)
				b=8;
			else if ((int)second[0]==57)
				b=9;
			else if ((int)second[0]==84)
				b=10;
			else if ((int)second[0]==74)
				b=11;
			else if ((int)second[0]==81)
				b=12;
			else if ((int)second[0]==75)
				b=13;
			else if ((int)second[0]==65)
				b=14;

			if (a>b && ((int)first[1]==(int)second[1]))
				flag=1;
		}

		if (flag==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

import java.io.*;
import java.util.*;

public class Test {
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	//String str=nextToken();
	//String[] s = str.split("\\s+");
	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }

	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	    String cards="6789TJQKA";
		String god = nextToken();
        String first = nextToken(), second = nextToken();
        boolean can = false;
        if (first.charAt(1) != second.charAt(1)) {
            if (first.charAt(1) == god.charAt(0)) {
                can = true;
            } else {
                can = false;
            }
        } else {
            if (cards.indexOf(first.charAt(0)) > cards.indexOf(second.charAt(0))) {
                can = true;
            }
        }
        writer.println(can ? "YES" : "NO");
	}
}

import java.util.*;
import java.io.*;
//harish reddy anumula
public class CodeForces{
    public static void main (String[] args)throws java.lang.Exception{
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        String z = br.readLine();
        char trump = z.charAt(0);
        String[] z1 = br.readLine().split(" ");
        String on = z1[0];
        String tw = z1[1];
        int one = value(on.charAt(0));
        int two = value(tw.charAt(0));
        if(on.charAt(1)==trump && tw.charAt(1)!=trump){
            pw.println("YES");
        }
        else if(on.charAt(1)!=tw.charAt(1)){
            pw.println("NO");
        }
        else{
            if(one>two){
                pw.println("YES");
            }
            else{
                pw.println("NO");
            }
        }
        pw.close();
    }
    public static int value(char c){
        if(c=='6') return 6;
        if(c=='7') return 7;
        if(c=='8') return 8;
        if(c=='9') return 9;
        if(c=='T') return 10;
        if(c=='J') return 11;
        if(c=='Q') return 12;
        if(c=='K') return 13;
        if(c=='A') return 14;
        return 0;
    }
}

import java.io.IOException;
import java.util.Scanner;

public class sample {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        StringBuilder x = new StringBuilder("123456789TJQKA");
        char t = in.next().charAt(0);
        String t1 = in.next();
        String t2 = in.next();
        boolean win = false;
        if (t1.charAt(1) == t)
            win = true;
        if (t1.charAt(1) == t2.charAt(1))
            if (x.indexOf(t1.charAt(0)+"") > x.indexOf(t2.charAt(0)+""))
                win = true;
            else
                win = false;
        if (win)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {
    private static BufferedReader in;
    private static StringTokenizer st;
    private static PrintWriter out;

    public static void main(String[] args) throws NumberFormatException, IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        String suit = next();
        String s1 = next();
        String s2 = next();
        if(s1.charAt(1) == s2.charAt(1)){
            if(getRank(s1.charAt(0)) > getRank(s2.charAt(0))){
                System.out.println("YES");
                return;
            }
        }else{
            if(suit.equals(s1.charAt(1)+"")){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

    private static int getRank(char charAt) {
        String a[] = {"6", "7", "8", "9", "T", "J", "Q", "K","A"};
        for (int i = 0; i < a.length; i++) {
            if(a[i].equals(charAt+"")){
                return i;
            }
        }
        return -1;
    }

    static String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
    static int nextInt() throws NumberFormatException, IOException{
        return Integer.parseInt(next());
    }
    static long nextLong() throws NumberFormatException, IOException{
        return Long.parseLong(next());
    }

    static double nextDouble() throws NumberFormatException, IOException{
        return Double.parseDouble(next());
    }

}

import java.io.*;
import java.util.*;

/*
Good, better, best. Never let it rest. 'Til your good is better and your better is best.
 */

public class Main {

    // SOLVER
    static void solve() {
        // INPUT OUTPUT
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int testCase = 1;
        StringBuilder result = new StringBuilder();
        while (--testCase >= 0)
        /**************************************************************************/
        {
            // SOLVE
            String trump = in.nextLine().trim();
            String[] cards = in.nextLine().trim().split("\\s+");
            HashMap<Character, Integer> assignedValue = new HashMap<>();
            int incrementValue = 0;
            assignedValue.put('6', ++incrementValue);
            assignedValue.put('7', ++incrementValue);
            assignedValue.put('8', ++incrementValue);
            assignedValue.put('9', ++incrementValue);
            assignedValue.put('T', ++incrementValue);
            assignedValue.put('J', ++incrementValue);
            assignedValue.put('Q', ++incrementValue);
            assignedValue.put('K', ++incrementValue);
            assignedValue.put('A', ++incrementValue);

            if (trump.charAt(0) == cards[0].charAt(1) && trump.charAt(0) != cards[1].charAt(1)) {
                result.append("YES");
                break;
            }
            if (assignedValue.get(cards[0].charAt(0)) > assignedValue.get(cards[1].charAt(0)) && cards[0].charAt(1) == cards[1].charAt(1)) {
                result.append("YES");
            }else {
                result.append("NO");
            }
            /*****************************************/
        }
        pw.println(result.toString().trim());
        // *************************************
        {
            pw.close();
        }
    }

    /**************************************************************************
     *************************************************************************/
    // DRIVER CODE
    public static void main(String[] args) {
        solve();
    }

    // FAST INPUT
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
Scanner s = new Scanner (System.in);

char S=s.next().charAt(0);
String First=s.next(),Second=s.next();

if ((First.charAt(1)==S && Second.charAt(1)!=S) || (First.charAt(1)==Second.charAt(1) && Stronger(First.charAt(0),Second.charAt(0))))
{
    System.out.println("YES");
} else {
    System.out.println("NO");
}
   }

    private static boolean Stronger(char _1, char _2) {
        HashMap<Character,Integer> E = new HashMap<Character,Integer>();
        E.put('6',0);E.put('7', 1);E.put('8', 2);E.put('9', 3);
        E.put('T', 4);E.put('J', 5);E.put('Q', 6);E.put('K', 7);
        E.put('A', 8);
        int val1=E.get(_1);
        int val2=E.get(_2);
        return val1>val2;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * User: Samuel
 * Date: 08-19-11
 * Time: 09:11 AM
 */
public class A {
    public static void main(String[] args) throws IOException {
        new A().solve();
    }

    private void solve() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String suit = in.readLine();
        String split[] = in.readLine().split(" ");
        String vals = "6789TJQKA";

        if (split[0].charAt(1) == split[1].charAt(1)) {
            if (vals.indexOf(split[0].charAt(0)) > vals.indexOf(split[1].charAt(0))) {
                System.out.println("YES");
                System.exit(0);
            } else {
                System.out.println("NO");
                System.exit(0);
            }
        }

        if (split[0].charAt(1) == suit.charAt(0)) {
            System.out.println("YES");
            System.exit(0);
        }
        System.out.println("NO");
        System.exit(0);
    }
}

import java.util.Scanner;

public class Problem_106A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char l = in.next().charAt(0);
        String s1 = in.next();
        String s2 = in.next();
        boolean winning = false;
        if(s1.charAt(1) == l && s2.charAt(1) != l)
            winning = true;
        if(s1.charAt(1) == s2.charAt(1) && value(s1.charAt(0)) > value(s2.charAt(0)))
            winning = true;
        if(!winning)
            System.out.println("NO");
        else
            System.out.println("YES");

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

import java.io.*;
import java.util.*;
public class B82 {

    private void solve() throws IOException {
        String a = "6789TJQKA";
        char n = nextToken().charAt(0);
        String x = nextToken();
        String y = nextToken();

        int i =a.indexOf(x.charAt(0));
        int j =a.indexOf(y.charAt(0));

          if (x.charAt(1) == n&&x.charAt(1)!=y.charAt(1)) {
            System.out.println("YES");
        } else if (x.charAt(1) == y.charAt(1)) {
            if (i>= j)
                System.out.println("YES");
            else
                System.out.println("NO");

        } else
            System.out.println("NO");
    }
    public static void main(String[] args) {

        new B82().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}

import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;

public class card_game {

	public static void main(String[] args) throws Exception {
		new card_game().run();
	}

	public void run() throws Exception {
		FastIO file = new FastIO();
		String ranking = "6789TJQKA";
		char trump = file.nextLine().charAt(0);
		char[] a = file.next().toCharArray();
		char[] b = file.next().toCharArray();
		if (a[1] == trump && b[1] != trump) {
			System.out.println("YES");
		}
		else if (a[1] == b[1] && ranking.indexOf(a[0]) > ranking.indexOf(b[0])) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}

	public static class FastIO {
		BufferedReader br;
		StringTokenizer st;

		public FastIO() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static long pow(long n, long p, long mod) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n % mod;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2, mod);
			return (temp * temp) % mod;
		} else {
			long temp = pow(n, p / 2, mod);
			temp = (temp * temp) % mod;
			return (temp * n) % mod;

		}
	}

	public static long pow(long n, long p) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2);
			return (temp * temp);
		} else {
			long temp = pow(n, p / 2);
			temp = (temp * temp);
			return (temp * n);

		}
	}

	public static long gcd(long x, long y) {
		if (x == 0)
			return y;
		else
			return gcd(y % x, x);
	}

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}
}

import java.util.Scanner;

/**
 *
 * @author Muhammad.Bahaa
 */
public class ACardGame {

    public static void main(String[] args) {
        char cards[] = {'S', 'H', 'D', 'C'};
        char symbol[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
        String trump, card1, card2;
        Scanner in = new Scanner(System.in);
        trump = in.next();
        card1 = in.next();
        card2 = in.next();

        if (card1.contains(trump) && !card2.contains(trump)) {
            System.out.println("YES");
        } else if (card2.contains(trump)&& !card1.contains(trump)) {
            System.out.println("NO");
        } else if (new String(symbol).indexOf(card1.charAt(0)) > new String(symbol).indexOf(card2.charAt(0)) && card1.charAt(1) == card2.charAt(1)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

import java.util.*;
public class Dyrak {

	/**
	 * @param args
	 */
	Scanner sc;
	String res = "NO";
	Dyrak() {
		go();
	}
	public void go() {
		sc = new Scanner(System.in);
		String base = sc.nextLine();
		String hod = sc.nextLine();
		String fmast = hod.charAt(1) + "";
		String fcifra = hod.charAt(0) + "";
		String smast = hod.charAt(4) + "";
		String scifra = hod.charAt(3) + "";

		if ((fmast.equals(base)) & (!smast.equals(base))) {
			res = "YES";
		}
		if ((!smast.equals(base)) & (smast.equals(fmast)) || (smast.equals(base)) & (smast.equals(fmast))) {
			switch (fcifra){
				case "A":
					if (!scifra.equals("A")) {
						res = "YES";
					}
					break;
				case "K":
					if ((!scifra.equals("A")) & (!scifra.equals("K"))) {
						res = "YES";
					}
					break;
				case "Q":
					if ((!scifra.equals("A")) & (!scifra.equals("K")) & (!scifra.equals("Q"))) {
						res = "YES";
					}
					break;
				case "J":
					if ((!scifra.equals("A")) & (!scifra.equals("K")) & (!scifra.equals("Q")) & (!scifra.equals("J"))) {
						res = "YES";
					}
					break;
				case "T":
					if ((!scifra.equals("A")) & (!scifra.equals("K")) & (!scifra.equals("Q")) & (!scifra.equals("J"))  & (!scifra.equals("T"))) {
						res = "YES";
					}
					break;
				default:
					if ((!scifra.equals("A")) & (!scifra.equals("K")) & (!scifra.equals("Q")) & (!scifra.equals("J")) & (!scifra.equals("T")))
						{
						if ((Integer.parseInt(fcifra) > Integer.parseInt(scifra)) & (fmast.equals(smast))) {
							res ="YES";
						}
					}
			}
		}
		System.out.println(res);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Dyrak();
	}

}

import java.util.Hashtable;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String cad=scan.nextLine();
		String cartas[]=scan.nextLine().split(" ");
		Hashtable<String, Integer>valor=new Hashtable<String,Integer>();
		valor.put("6", 6);
		valor.put("7", 7);
		valor.put("8", 8);
		valor.put("9", 9);
		valor.put("T", 10);
		valor.put("J", 11);
		valor.put("Q", 12);
		valor.put("K", 13);
		valor.put("A", 14);

		if(valor.get(cartas[0].charAt(0)+"")>valor.get(cartas[1].charAt(0)+"") && cartas[0].charAt(1)==cartas[1].charAt(1) || valor.get(cartas[0].charAt(0)+"")>valor.get(cartas[1].charAt(0)+"") && cartas[0].charAt(1)==cad.charAt(0)){
			System.out.println("YES");
		}else if(cartas[0].charAt(1)==cad.charAt(0) && cartas[1].charAt(1)!=cad.charAt(0)){

			System.out.println("YES");

		}else {

			System.out.println("NO");

		}

	}

}

import java.util.*;
import java.lang.*;
import java.io.*;

public class Card_Game {

	public static void main(String[] args) throws java.lang.Exception
    {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		StringTokenizer st = new StringTokenizer(br.readLine());
		String a=st.nextToken(),b=st.nextToken();
		char c[]= { '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
		if(a.charAt(1)==b.charAt(1)){
			int m=0,n=0;
			for(int i=0; i<c.length; i++) {
				if(a.charAt(0)==c[i]) m=i;
				if(b.charAt(0)==c[i]) n=i;
			}
			System.out.println(m>n?"YES":"NO");
		}else if(a.charAt(1)==s.charAt(0)){
			if(a.charAt(1)!=b.charAt(1)) System.out.println("YES");
			else {
				int m=0,n=0;
				for(int i=0; i<c.length; i++) {
					if(a.charAt(0)==c[i]) m=i;
					if(b.charAt(0)==c[i]) n=i;
				}
				System.out.println(m>n?"YES":"NO");
			}
		}else {
			System.out.println("NO");
		}

	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;

public class Main {

    static int cycle=0;
    public static void main(String[] args) throws NumberFormatException, IOException {

    BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pr=new PrintWriter(System.out);

HashMap<Character,Character> map=new HashMap<Character,Character>();
map.put('6', '1');
map.put('7', '2');
map.put('8', '3');
map.put('9', '4');
map.put('T', '5');
map.put('J', '6');
map.put('Q', '7');
map.put('K', '8');
map.put('A', '9');

char tr=r.readLine().charAt(0);
    String s=r.readLine();

    char n1=map.get(s.charAt(0));
    char t1=s.charAt(1);
    char n2=map.get(s.charAt(3));
    char t2=s.charAt(4);

    if(t1==tr&&t2!=tr)
    {
        pr.println("YES");
    }
    else
    if(t1==t2)
    {
        if(n1>n2)
        {
            pr.println("YES");
        }
        else
            pr.println("NO");

    }
    else
        pr.println("NO");

pr.flush();
pr.close();
}
}

import java.util.Scanner;

public class A106 {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        String card = "6789TJQKA";
        char koz = in.nextLine().charAt(0);
        String first = in.next();
        String second = in.next();
        if (first.charAt(1)==second.charAt(1) && card.indexOf(first.charAt(0)+"")>card.indexOf(second.charAt(0)+"")) {
            System.out.println("YES");
        } else
            if (first.charAt(1)==koz && second.charAt(1)!=koz) System.out.println("YES"); else System.out.println("NO");
    }
}

import java.io.*;
import java.util.StringTokenizer;

public class B82 {

    private void solve() throws IOException {

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

        char n = nextToken().charAt(0);

        String x = nextToken();
        String y = nextToken();

        char d = x.charAt(0);

        char f = y.charAt(0);

        int i = 0;
        for (; i < a.length; i++) {
            if (d == a[i])
                break;

        }
        int j = 0;
        for (; j < a.length; j++) {
            if (f == a[j])
                break;

        }
        if (x.charAt(1) == n && y.charAt(1) == n) {
            if (i >= j)
                System.out.println("YES");
            else
                System.out.println("NO");
        } else if (x.charAt(1) == n) {
            System.out.println("YES");
        } else if (x.charAt(1) == y.charAt(1)) {
            if (i>= j)
                System.out.println("YES");
            else
                System.out.println("NO");

        } else
            System.out.println("NO");
    }

    public static void main(String[] args) {

        new B82().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}

import java.util.Arrays;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskA {

    String ranks = "6789TJQKA";

    void run(){
        String trump = next();
        String first = next();
        String second = next();

        if(first.charAt(1) == trump.charAt(0)) {
            if(second.charAt(1) == trump.charAt(0)) {
                if(ranks.indexOf(first.charAt(0)) > ranks.indexOf(second.charAt(0))) {
                    System.out.println("YES");
                }
                else {
                    System.out.println("NO");
                }
            }
            else {
                System.out.println("YES");
            }
        }
        else {
            if(first.charAt(1) == second.charAt(1)) {
                if(ranks.indexOf(first.charAt(0)) > ranks.indexOf(second.charAt(0))) {
                    System.out.println("YES");
                }
                else {
                    System.out.println("NO");
                }
            }
            else {
                System.out.println("NO");
            }
        }

    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskA().run();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A_82_CardGame {

    private static String strength = "6789TJQKA";

    public static void main(String[] args) {
        try {
            BufferedReader input = new BufferedReader(new InputStreamReader(
                    System.in));

            String trumpCard = input.readLine();

            String line = input.readLine();
            String[] strs = line.split(" ");
            String firstCard = strs[0];
            String secondCard = strs[1];

            if (firstCard.charAt(1) == secondCard.charAt(1)) {
                if (getPossition(firstCard.charAt(0)) > getPossition(secondCard
                        .charAt(0))) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            } else {
                if (firstCard.charAt(1) == trumpCard.charAt(0)
                        && secondCard.charAt(1) != trumpCard.charAt(0)) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int getPossition(char ch) {
        int poss = 0;
        for (int i = 0; i < strength.length(); i++) {
            if (strength.charAt(i) == ch) {
                poss = i;
                break;
            }
        }
        return poss;
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Stack;
import java.util.StringTokenizer;

public class Solution
{
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = null;

    private void solve() throws IOException
    {
        HashMap<String, Integer> hm = new HashMap<String, Integer>();
        hm.put("6", 0);
        hm.put("7", 1);
        hm.put("8", 2);
        hm.put("9", 3);
        hm.put("T", 4);
        hm.put("J", 5);
        hm.put("Q", 6);
        hm.put("K", 7);
        hm.put("A", 8);
        String main = nextToken();
        String first = nextToken();
        String second = nextToken();
        boolean is = false;
        if(first.substring(1, 2).equals(second.substring(1, 2)))
        {
            if(hm.get(first.substring(0, 1)) > hm.get(second.substring(0, 1)))
            {
                is = true;
            }

        }

        if(!is && !second.substring(1, 2).equals(main) && first.substring(1, 2).equals(main))
        {
            is = true;
        }

        System.out.println(is ? "YES" : "NO");
    }

    String nextToken() throws IOException
    {
        if (st == null || !st.hasMoreTokens())
        {
            st = new StringTokenizer(bf.readLine());
        }

        return st.nextToken();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(nextToken());
    }

    public static void main(String args[]) throws IOException
    {
        new Solution().solve();
    }

}

import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
public class JavaApplication13 {
    public static void main(String[] args) {
    Scanner in=new Scanner(System.in);
    String suit = in.nextLine();
    String str = in.nextLine();
    String[] s = str.split(" ");
    char[] c = {'6','7','8','9','T','J','Q','K','A'};
    int temp1 = 0,temp2 = 0;
    for(int i=0;i<c.length;i++){
        if(s[0].charAt(0) == c[i])
        temp1 = i;
        if(s[1].charAt(0) == c[i])
        temp2 = i;
    }
    if((temp2<temp1 && s[1].charAt(1) == s[0].charAt(1)) || (s[1].charAt(1) != suit.charAt(0) && suit.charAt(0) == s[0].charAt(1)) || (temp2<temp1 && s[1].charAt(1) == suit.charAt(0) && suit.charAt(0) == s[0].charAt(1)))
	System.out.println("YES");
	else System.out.println("NO");
    }
}

import java.util.Scanner;

public class Testing {
  public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        String g=scan.next();
        String g1=scan.next();
        String g2=scan.next();
        String f="6789TJQKA";
        if(g1.charAt(1)==g.charAt(0)&&g2.charAt(1)!=g.charAt(0))System.out.println("YES");
        else if(g2.charAt(1)+""==g)System.out.println("NO");
        else if(g1.charAt(1)==g2.charAt(1))if(f.indexOf(g1.charAt(0))>f.indexOf(g2.charAt(0)))System.out.println("YES");
        else System.out.println("NO");
        else System.out.println("NO");

}}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A {

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

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String trump = reader.readLine();
		String cards = reader.readLine();
		String result = "NO";

		if (cards.charAt(1) == trump.charAt(0) && cards.charAt(4) != trump.charAt(0)) {
			result = "YES";
		} else {
			if (cards.charAt(1) == cards.charAt(4) && beats(cards)) {
				result = "YES";
			}
		}
		System.out.println(result);
	}

	public static boolean beats(String cards) {
		char firstCard = cards.charAt(0);
		char secondCard = cards.charAt(3);
		int firstCardPos = 0;
		int secondCardPos = 0;
		for (int i = 0; i<order.length;i++) {
			if (order[i] == firstCard) {
				firstCardPos = i;
			}
			if (order[i] == secondCard) {
				secondCardPos = i;
			}
		}
		return firstCardPos > secondCardPos;
	}

}

import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String trump = scan.nextLine();
    String l = scan.nextLine();
    char c1rank = l.charAt(0);
    char c1suit = l.charAt(1);
    char c2rank = l.charAt(3);
    char c2suit = l.charAt(4);
    if (c1suit == trump.charAt(0) && c2suit != trump.charAt(0))
      System.out.println("YES");
    else if (c2suit != c1suit)
      System.out.println("NO");
    else if (c1rank == 'A' && c2rank != 'A')
      System.out.println("YES");
    else if (c1rank == 'K' && c2rank !='A' && c2rank != 'K')
      System.out.println("YES");
    else if (c1rank == 'Q' && c2rank != 'A' && c2rank != 'K' && c2rank !='Q')
      System.out.println("YES");
    else if (c1rank == 'J' && c2rank != 'A' && c2rank != 'K' && c2rank != 'Q' && c2rank != 'J')
      System.out.println("YES");
    else if (c1rank == 'T' && c2rank - '9' <= 0 && c2rank - '6' >= 0)
      System.out.println("YES");
    else if (c1rank > c2rank && c1rank - '9' <= 0 && c1rank - '6' >= 0 && c2rank - '9' <= 0 && c2rank - '6' >= 0)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
}

import java.util.HashMap;
import java.util.Scanner;

public class CF106A {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        HashMap<Character,Integer> hm=new HashMap<>();
        hm.put('6',1);
        hm.put('7',2);
        hm.put('8',3);
        hm.put('9',4);
        hm.put('T',5);
        hm.put('J',6);
        hm.put('Q',7);
        hm.put('K',8);
        hm.put('A',9);
        String trump=s.nextLine();
        String a=s.next();
        String b=s.next();
        if(a.charAt(1)==trump.charAt(0) && b.charAt(1)!=trump.charAt(0)){
            System.out.println("YES");
        }
        else{
            if(hm.get(a.charAt(0))>hm.get(b.charAt(0)) && a.charAt(1)==b.charAt(1)){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }

    }
}

import java.util.Scanner;

/**
 *
 * @author Guest
 */
public class JavaApplication26 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner ab = new Scanner(System.in);
        char c = ab.nextLine().charAt(0);

        String s = ab.nextLine();
        String [] sa = s.split(" ");

        String d = "6789TJQKA";

        if(sa[0].charAt(1)==sa[1].charAt(1)){
        if(d.indexOf(sa[0].charAt(0))>d.indexOf(sa[1].charAt(0)))
                System.out.println("YES");
        else System.out.println("NO");
        }else if(sa[0].charAt(1)==c)
            System.out.println("YES");
          else if(sa[1].charAt(1)==c)
            System.out.println("NO");
          else System.out.println("NO");

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {

    public static boolean compareCards(char first,char second)
    {
        if (first>'9')
            switch(first)
            {
                case 'T': return second<='9';
                case 'J': return second<='9' || second=='T';
                case 'Q': return second<='9' || second=='T' || second=='J';
                case 'K': return second<='9' || second=='T' || second=='J' || second=='Q';
                case 'A': return second<='9' || second=='T' || second=='J' || second=='Q' || second=='K';
            }
        else return first>second;
        return false;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        //Scanner in=new Scanner(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        String trump=in.readLine();
        String[] cards=in.readLine().split(" ");
        if (cards[0].contains(trump) && !cards[1].contains(trump))
            out.print("YES");
        else if (!cards[0].contains(trump) && cards[1].contains(trump))
                out.print("NO");
        else if (compareCards(cards[0].charAt(0),cards[1].charAt(0)) && cards[0].charAt(1)==cards[1].charAt(1)) out.print("YES");
        else out.print("NO");
        out.close();
    }

}

// card

import java.util.*;
import java.io.*;

public class card
{
	public static void main(String[] args) throws Exception
	{
		new card(new Scanner(System.in));
		//new card(new Scanner(new File("card.in")));
	}

	public card(Scanner in)
	{
		// Read in the trump suit.
		String trumpStr = in.next();
		char trump = trumpStr.charAt(0);

		// Read in the two cards.
		String[] card = new String[2];
		card[0] = in.next();
		card[1] = in.next();

		// If both cards are of the same suit:
		if (card[0].charAt(1)==card[1].charAt(1))
		{
			// Assign a value for each card.
			int[] cardVal = new int[2];

			// For each card:
			for (int i=0; i<2; i++)
			{
				char val = card[i].charAt(0);
				if (val=='T')
				{
					cardVal[i] = 10;
				}
				else if (val=='J')
				{
					cardVal[i] = 11;
				}
				else if (val=='Q')
				{
					cardVal[i] = 12;
				}
				else if (val=='K')
				{
					cardVal[i] = 13;
				}
				else if (val=='A')
				{
					cardVal[i] = 14;
				}
				else
				{
					String valStr = Character.toString(val);
					cardVal[i] = Integer.parseInt(valStr);
				}
			}
			if (cardVal[0]>cardVal[1])
			{
				System.out.println("YES");
				return;
			}
			else
			{
				System.out.println("NO");
				return;
			}
		}
		// If card 1 is a trump card:
		else if (card[0].charAt(1)==trump)
		{
			System.out.println("YES");
			return;
		}
		// Otherwise card 1 wins.
		else
		{
			System.out.println("NO");
			return;
		}
	}
}

import java.io.*;
import java.util.*;

public class CF82A {

	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	// private static Timer t = new Timer();

	public CF82A() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
	}

	String next() throws IOException {
		while (st == null || !st.hasMoreElements())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	boolean hasNext() {
		if (st != null && st.hasMoreElements())
			return true;

		try {
			while (st == null || !st.hasMoreElements())
				st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			return false;
		}

		return true;
	}

	String nextLine() throws IOException {
		return br.readLine();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	void solve() throws IOException {
		HashMap<String, Integer> map = new HashMap<>();
		String[] S = { "6", "7", "8", "9","T", "J", "Q", "K", "A" };
		int[] A = { 6, 7, 8, 9, 10, 11, 12, 13, 14 };
		for (int i = 0; i < S.length; i++) {
			map.put(S[i], A[i]);
		}

		String s = next();
		char[] S1 = next().toCharArray();
		char[] S2 = next().toCharArray();

		String lastS1 = "" + S1[1], lastS2 = "" + S2[1];
		if (lastS1.equals(s)) {
			if (lastS2.equals(s)) {
				if (map.get(""+S1[0]) > map.get(""+S2[0]))
					pw.println("YES");
				else
					pw.println("NO");
			}else {
				pw.println("YES");
			}
		}else if( lastS2.equals(s)) {
			pw.println("NO");
		}else {
			if(map.get(""+S1[0]) > map.get(""+S2[0]) && S1[1] == S2[1]) {
				pw.println("YES");
			}else
				pw.println("NO");
		}

		pw.flush();
	}

	public static void main(String[] args) throws IOException {
		new CF82A().solve();
	}
}

import java.util.Hashtable;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String cad=scan.nextLine();
		String cartas[]=scan.nextLine().split(" ");
		Hashtable<String, Integer>valor=new Hashtable<String,Integer>();
		valor.put("6", 6);
		valor.put("7", 7);
		valor.put("8", 8);
		valor.put("9", 9);
		valor.put("T", 10);
		valor.put("J", 11);
		valor.put("Q", 12);
		valor.put("K", 13);
		valor.put("A", 14);

		if(valor.get(cartas[0].charAt(0)+"")>valor.get(cartas[1].charAt(0)+"") && cartas[0].charAt(1)==cartas[1].charAt(1) || valor.get(cartas[0].charAt(0)+"")>valor.get(cartas[1].charAt(0)+"") && cartas[0].charAt(1)==cad.charAt(0)){
			System.out.println("YES");
		}else if(cartas[0].charAt(1)==cad.charAt(0) && cartas[1].charAt(1)!=cad.charAt(0)){

			System.out.println("YES");

		}else {

			System.out.println("NO");

		}

	}

}

import java.io.*;
import java.util.*;
public class CardGame {
    public static int getInt(char value) {
        //"6", "7", "8", "9", "T", "J", "Q", "K" and "A"
        if(value == 'T') return 10;
        if(value == 'J') return 11;
        if(value == 'Q') return 12;
        if(value == 'K') return 13;
        if(value == 'A') return 14;
        return value - '0';
    }
    public static boolean win(char trump, char value1, char suit1, char value2, char suit2) {
        int val1 = getInt(value1);
        int val2 = getInt(value2);
        if(suit1 == suit2) {
            if(val1 > val2) return true;
            else return false;
        }
        if(suit1 == trump)
            return true;
        return false;
    }
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        char trump = sc.next().charAt(0);
        String card1 = sc.next();
        String card2 = sc.next();
        if(win(trump, card1.charAt(0), card1.charAt(1), card2.charAt(0), card2.charAt(1))) {
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
        sc.close();
    }
}

import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.ArrayList;
import java.text.DecimalFormat;

public class Main {
    public static void cout(String s)
    {
        System.out.println(s);

    }
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
           String s=in.next();
           char c=s.charAt(0);
           String s1=in.next();

           String s2=in.next();

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

           boolean ff=false;
           if(s1.charAt(1)==c&&s2.charAt(1)!=c)
               ff=true;
           if(s1.charAt(1)==s2.charAt(1))
           {
               int i,j;
               for(i=0;i<9;i++)
                   if(a[i]==s1.charAt(0))
                       break;
               for(j=0;j<9;j++)
                   if(a[j]==s2.charAt(0))
                       break;
               if(i>j)
                   ff=true;

           }
           if(ff)
               cout("YES");
           else cout("NO");

        }
    }

}

import java.io.IOException;
import java.util.Scanner;

public class sample {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        StringBuilder x = new StringBuilder("TJQKA");
        char t = in.next().charAt(0);
        String t1 = in.next();
        String t2 = in.next();
        boolean win = false;
        if (t1.charAt(1) == t)
            win = true;
        if (t1.charAt(1) == t2.charAt(1))
            if (x.indexOf(t1.charAt(0)+"") > x.indexOf(t2.charAt(0)+""))
                win = true;
            else
                win = false;
        if (win)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

import java.util.*;

public class test {
	static HashMap<Character,Integer> hm=new HashMap<Character,Integer>();
	static int compare(char a, char b)
	{
		if(a>='A' && a<='T' && b>='A' && b<='T')
		{
			return hm.get(a)-hm.get(b);
		}
		else
			return a-b;
	}
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);

	 hm.put('T',0);
	 hm.put('J', 1);
	 hm.put('Q', 2);
	 hm.put('K',3);
	 hm.put('A', 4);

	 char T=sc.next().charAt(0);
	 char[] C1=sc.next().toCharArray();
	 char[] C2=sc.next().toCharArray();

	 boolean result;

	 if(C1[1]==T)
		 result=true;
	 else if(C1[1]!=C2[1])
		 result=false;
	 else
	 {
		 if(compare(C1[0],C2[0])>0)
			 result=true;
		 else
			 result=false;
	 }
	 System.out.println(result?"YES":"NO");

 	}

}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class CardGame implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);

    public void solve() {
        char trump = in.next().charAt(0);
        char[] a = in.next().toCharArray(), b = in.next().toCharArray();
        Map<Character, Integer> map = new HashMap<Character, Integer>() {{
            put('6', 6);
            put('7', 7);
            put('8', 8);
            put('9', 9);
            put('T', 10);
            put('J', 11);
            put('Q', 12);
            put('K', 13);
            put('A', 14);
        }};
        boolean wins;
        if (a[1] == trump) {
            wins = b[1] != trump || map.get(a[0]) > map.get(b[0]);
        } else {
            wins = b[1] != trump && map.get(a[0]) > map.get(b[0]);
        }
        out.println(wins ? "YES" : "NO");
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) throws IOException {
        try (CardGame instance = new CardGame()) {
            instance.solve();
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        a106 solver = new a106();
        solver.solve(1, in, out);
        out.close();
    }

    static class a106 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String m = in.next();
            String fc = in.next();
            String sc = in.next();
            if (fc.charAt(1) == m.charAt(0) && sc.charAt(1) != m.charAt(0)) {
                out.println("YES");
            } else if (fc.charAt(1) != sc.charAt(1)) {
                out.println("NO");
            } else {
                int fcP;
                switch (fc.charAt(0)) {
                    case 'T':
                        fcP = 10;
                        break;
                    case 'J':
                        fcP = 11;
                        break;
                    case 'Q':
                        fcP = 12;
                        break;
                    case 'K':
                        fcP = 13;
                        break;
                    case 'A':
                        fcP = 14;
                        break;
                    default:
                        fcP = fc.charAt(0) - '0';
                }
                int scP;
                switch (fc.charAt(0)) {
                    case 'T':
                        scP = 10;
                        break;
                    case 'J':
                        scP = 11;
                        break;
                    case 'Q':
                        scP = 12;
                        break;
                    case 'K':
                        scP = 13;
                        break;
                    case 'A':
                        scP = 14;
                        break;
                    default:
                        scP = fc.charAt(0) - '0';
                }
                if (fcP > scP) out.println("YES");
                else out.println("NO");
            }
        }

    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CardGame {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tokenizer;
	final double EPSILON = 1e-6;
	final int INF = (1 << 31) - 1;
	String suit;
	String firstCard, secondCard;

	CardGame() {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));
	}

	public void close() throws IOException {
		out.close();
		in.close();
	}

	public void enter() throws IOException {
		suit = nextToken();
		firstCard = nextToken();
		secondCard = nextToken();
		solve();
	}

	boolean canBeat() {
		if (firstCard.charAt(1) == secondCard.charAt(1)
				&& firstCard.charAt(0) > secondCard.charAt(0))
			return true;
		if ((firstCard.charAt(1) + "").equals(suit))
			return true;

		return false;
	}

	public void solve() {
		if(canBeat())
			out.println("YES");
		else
			out.println("NO");

	}

	public static void main(String[] args) throws IOException {
		CardGame obj = new CardGame();
		obj.enter();
		obj.close();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/*
 * Created on 11.11.2011 by neust-ai
 */

public class main {

    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String k=in.readLine();
        String result="NO";
        String[] cards = in.readLine().split(" ");
        switch(cards[0].charAt(0))
        {
            case 'T': cards[0].replace('T','A'); break;
            case 'J': cards[0].replace('J','B'); break;
            case 'Q': cards[0].replace('Q','C'); break;
            case 'K': cards[0].replace('K','D'); break;
            case 'A': cards[0].replace('A','E'); break;
        }
        switch(cards[1].charAt(0))
        {
            case 'T': cards[0].replace('T','A'); break;
            case 'J': cards[0].replace('J','B'); break;
            case 'Q': cards[0].replace('Q','C'); break;
            case 'K': cards[0].replace('K','D'); break;
            case 'A': cards[0].replace('A','E'); break;
        }
        if (cards[0].charAt(0)>cards[1].charAt(0)&&
           cards[0].charAt(1)==cards[1].charAt(1)||
           cards[0].charAt(1)==k.charAt(0)&&cards[1].charAt(1)==k.charAt(0)&&cards[0].charAt(0)>cards[1].charAt(0)||
           cards[0].charAt(1)==k.charAt(0)&&cards[1].charAt(1)!=k.charAt(0))
        {
            result="YES";
        }
        out.print(result);
        out.close();
    }
}

import java.util.Hashtable;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String cad=scan.nextLine();
		String cartas[]=scan.nextLine().split(" ");
		Hashtable<String, Integer>valor=new Hashtable<String,Integer>();
		valor.put("6", 6);
		valor.put("7", 7);
		valor.put("8", 8);
		valor.put("9", 9);
		valor.put("T", 10);
		valor.put("J", 11);
		valor.put("Q", 12);
		valor.put("K", 13);
		valor.put("A", 14);

		if(valor.get(cartas[0].charAt(0)+"")>valor.get(cartas[1].charAt(0)+"") && cartas[0].charAt(1)==cartas[1].charAt(1) || valor.get(cartas[0].charAt(0)+"")>valor.get(cartas[1].charAt(0)+"") && cartas[0].charAt(1)==cad.charAt(0) || cartas[0].charAt(1)==cad.charAt(0)  ){
			System.out.println("YES");
		}else if(cartas[0].charAt(1)==cad.charAt(0) && cartas[1].charAt(1)!=cad.charAt(0)){

			System.out.println("YES");

		}else {

			System.out.println("NO");

		}

	}

}

import java.util.Arrays;
import java.util.Scanner;

public class Buffread {
 public static void main(String args[])
 {
   try{
   //  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     Scanner sc =new Scanner(System.in);
    // Set<Double> set = new HashSet<Double>();
     String card = "6789TJQKA";
     String tramp=sc.nextLine();
     String ch = sc.nextLine();
    // System.out.println(card.indexOf(ch.charAt(0)));
    // System.out.println(card.indexOf(ch.charAt(3)));
     if(ch.charAt(1) == tramp.charAt(0) && tramp.charAt(0) == ch.charAt(4))
          if(card.indexOf(ch.charAt(0)) > card.indexOf(ch.charAt(3)))
              System.out.println("YES");
          else
              System.out.println("NO");

     else if(ch.charAt(1) == tramp.charAt(0) && tramp.charAt(0) != ch.charAt(4))
          System.out.println("YES");

     else if(ch.charAt(1) != tramp.charAt(0) && tramp.charAt(0) != ch.charAt(4))
         if(card.indexOf(ch.charAt(0)) > card.indexOf(ch.charAt(3)))
                System.out.println("YES");
         else
             System.out.println("NO");
     else if(ch.charAt(1) != tramp.charAt(0) && tramp.charAt(0) == ch.charAt(4))
         System.out.println("NO");

     sc.close();
   } // End Of Try Block

    catch(Exception e) {
        e.printStackTrace();
    }
 } // End Of Main Block
}

import java.util.Scanner;

public class A_Card_Game {
public static void main(String[] args) {
    Scanner sc =  new Scanner(System.in);
    String tramp=sc.next();
    String first=sc.next();     String second=sc.next();
    String s="TJQKA";
if(!(first.charAt(1)+"").equals(tramp) && first.charAt(1)!=second.charAt(1)){
    System.out.println("NO"); return;
}
int x=0;int y=0;
if( first.charAt(1)==second.charAt(1) ){

    if( s.indexOf(first.charAt(0)+"")>-1 ){
     x= s.indexOf(first.charAt(0)+"")+10;
    }
    else
        x=Integer.parseInt(first.charAt(0)+"");
    if( s.indexOf(second.charAt(0)+"")>-1 ){
         y= s.indexOf(first.charAt(0)+"")+10;
    }
    else
        y=Integer.parseInt(second.charAt(0)+"");
    if(x<y){
        System.out.println("NO"); return;
    }
}
System.out.println("YES");
}
}

import java.util.Scanner;

public class CardGame {
	static String[] array = { "6", "7", "8", "9", "T", "J", "Q", "K", "A" };

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			String trump = scan.next();
			String first = scan.next();
			String second = scan.next();
			if (first.charAt(1) == trump.charAt(0)) {
				System.out.println("YES");
				continue;
			}
			if (second.charAt(1) == trump.charAt(0)) {
				System.out.println("NO");
				continue;
			}
			if (first.charAt(1) != second.charAt(1)) {
				System.out.println("NO");
				continue;
			}
			int index1 = getIndex(first.charAt(0) + "");
			int index2 = getIndex(second.charAt(0) + "");
			if (index1 < index2)
				System.out.println("NO");
			else
				System.out.println("YES");
		}
	}

	public static int getIndex(String s) {
		for (int i = 0; i < array.length; i++) {
			if (s.equals(array[i]))
				return i;
		}
		return -1;
	}
}

import java.util.*;

public class TCS1 {

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);

	String s=sc.nextLine();
	String str=sc.nextLine();
	String a=str.split(" ")[0];
	String b=str.split(" ")[1];
	String temp="6789TJQKA";

	if(a.charAt(1)==b.charAt(1)) {
		System.out.println("HOLA");
		if(temp.indexOf(a.charAt(0))>temp.indexOf(b.charAt(0)))System.out.println("YES");
		else System.out.println("NO");
	}
	else {
		if(a.charAt(1)==s.charAt(0))System.out.println("YES");
		else System.out.println("NO");
	}

	}
}

import java.util.*;
import java.math.*;
import java.io.*;
public class LOL {
    static int toVal(char c) {
        switch(c) {
            case 'T':
                return 4;
            case 'J':
                return 5;
            case 'Q':
                return 6;
            case 'K':
                return 7;
            case 'A':
                return 8;
            default:
                return c-'6';
        }
    }
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        char T = in.next().charAt(0);
        String a = in.next();
        String b = in.next();
        if (a.charAt(1) == T && b.charAt(1) != T)
            System.out.println("YES");
        else if (a.charAt(1) != T && b.charAt(1) == T)
            System.out.println("NO");
        else {
            int valA = toVal(a.charAt(0));
            int valB = toVal(b.charAt(0));
            if (valA > valB)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}

import java.io.*;
import java.util.*;

public class Main
{
	public static void main (String[]args)
	{
		Scanner read = new Scanner (new BufferedInputStream (System.in));

		String trump =read.next();

		char[] first = read.next().toCharArray();
		char[] second = read.next().toCharArray();

		int flag=0;

		if ((int)first[1]==(int)trump.charAt(0))
			flag=1;
		else
		{
			int a=0;
			int b=0;

			if ((int)first[0]==54)
				a=6;
			else if((int)first[0]==55)
				a=7;
			else if ((int)first[0]==56)
				a=8;
			else if ((int)first[0]==57)
				a=9;
			else if ((int)first[0]==84)
				a=10;
			else if ((int)first[0]==74)
				a=11;
			else if ((int)first[0]==81)
				a=12;
			else if ((int)first[0]==75)
				a=13;
			else if ((int)first[0]==65)
				a=14;

			if ((int)second[0]==54)
				b=6;
			else if((int)second[0]==55)
				b=7;
			else if ((int)second[0]==56)
				b=8;
			else if ((int)second[0]==57)
				b=9;
			else if ((int)second[0]==84)
				b=10;
			else if ((int)second[0]==74)
				b=11;
			else if ((int)second[0]==81)
				b=12;
			else if ((int)second[0]==75)
				b=13;
			else if ((int)second[0]==65)
				b=14;

			if (a>b && ((int)first[1]==(int)second[1]))
				flag=1;
		}

		if (flag==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

import java.io.*;
import java.util.*;

public class Main
{
	public static void main (String[]args)
	{
		Scanner read = new Scanner (new BufferedInputStream (System.in));

		String trump =read.next();

		char[] first = read.next().toCharArray();
		char[] second = read.next().toCharArray();

		int flag=0;

		if ((int)first[1]==(int)trump.charAt(0))
			flag=1;
		else
		{
			int a=0;
			int b=0;

			if ((int)first[0]==54)
				a=6;
			else if((int)first[0]==55)
				a=7;
			else if ((int)first[0]==56)
				a=8;
			else if ((int)first[0]==57)
				a=9;
			else if ((int)first[0]==84)
				a=10;
			else if ((int)first[0]==74)
				a=11;
			else if ((int)first[0]==81)
				a=12;
			else if ((int)first[0]==75)
				a=13;
			else if ((int)first[0]==65)
				a=14;

			if ((int)second[0]==54)
				b=6;
			else if((int)second[0]==55)
				b=7;
			else if ((int)second[0]==56)
				b=8;
			else if ((int)second[0]==57)
				b=9;
			else if ((int)second[0]==84)
				b=10;
			else if ((int)second[0]==74)
				b=11;
			else if ((int)second[0]==81)
				b=12;
			else if ((int)second[0]==75)
				b=13;
			else if ((int)second[0]==65)
				b=14;

			if (a>b)
				flag=1;
		}

		if (flag==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {

	private static BufferedReader input;	// ���� ����� ����� ������ ��������� ������ �� ������-���� ������
	private static PrintWriter output;	// ���� ����� ����� ������ ������ ������
	private static StreamTokenizer stoken;	// ���� ����� ������ ����� ��������� ���������� �������. �� ��������� ����������� - ������

	static String fin = "input";
	static String fout = "output";

	private static void solve() throws IOException{
		String master = input.readLine();
		String temp = input.readLine();
		String[] cards = temp.split(" ");

		if (cards[0].charAt(1)==cards[1].charAt(1)){
			int first = 0, second = 0;
			switch (cards[0].charAt(0)){
				case '6': {first = 6; break;}
				case '7': {first = 7; break;}
				case '8': {first = 8; break;}
				case '9': {first = 9; break;}
				case 'J': {first = 10; break;}
				case 'Q': {first = 11; break;}
				case 'K': {first = 12;break;}
				case 'A': {first = 13;break;}
			}

			switch (cards[1].charAt(0)){
				case '6': {second = 6;break;}
				case '7': {second = 7;break;}
				case '8': {second = 8;break;}
				case '9': {second = 9;break;}
				case 'J': {second = 10;break;}
				case 'Q': {second = 11;break;}
				case 'K': {second = 12;break;}
				case 'A': {second = 13;break;}
			}

			if (first>second){
				output.print("YES");
			}else{
				output.print("NO");
			}
		}else{
			if (cards[0].charAt(1)==master.charAt(0)){
				output.print("YES");
			}else{
				output.print("NO");
			}
		}
	}

	public static void main(String[] args) throws IOException {
		//�������� ������
		input = new BufferedReader(new InputStreamReader(System.in));
		output = new PrintWriter(System.out);

		//�������� ������
		//input = new BufferedReader(new FileReader(fin + ".txt"));
		//output = new PrintWriter(new FileWriter(fout + ".txt"));

		stoken = new StreamTokenizer(input);

		//����� �������
		solve();

		//�������� �����
		input.close();
		//����� ������
		output.flush();
		//�������� �����
		output.close();
	}

	//��������� 32-������ ����� �����
	private static int nextInt() throws IOException {
		return (int) nextDouble();
	}

	//��������� 64-������ ����� �����
	private static long nextLong() throws IOException {
		return (long) nextDouble();
	}

	//��������� 64-������ ������� �����
	private static double nextDouble() throws IOException {
		stoken.nextToken();
		return stoken.nval;
	}
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class test {
public static void main(String[] args) {
	String rank="6789TJQKA";
	Scanner s=new Scanner(System.in);
	String tump=s.next();
	String s1=s.next();
	String s2=s.next();

	if(s1.contains(tump+"")) System.out.println("YES");
	else if(s2.contains(tump+"")) System.out.println("NO");
	else{
		String a=s1.charAt(0)+"";
		String b=s2.charAt(0)+"";
		if(rank.indexOf(a)>rank.indexOf(b)) System.out.println("YES");
		else System.out.println("NO");
	}

}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author noflaxe
 */
public class Durak {

 public static boolean isHigher(char first, char second)
 {
 char[] n = {'6','7','8','9','T','J','Q','K','A'};
 int firstpos = 15;
 int secondpos = 15;
 int i = 0;
 while (firstpos == 15 || secondpos == 15)
 {
 if (first == n[i]) {
 firstpos = i; }
  if (second == n[i]) {
 secondpos = i; }
  i++;
 }
 if (firstpos > secondpos)
 {
 return true;
 }
 else {
 return false; }

}

 public static void main(String[] args) throws IOException
 {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        String trump=in.readLine();
        String[] hand = in.readLine().split(" ");
        if ((hand[0].contains(trump)) && (!hand[1].contains(trump))) {
        out.println("YES");
        } else if ((!hand[0].contains(trump)) && (hand[1].contains(trump))) {
            System.out.println("NO");
        } else if (isHigher(hand[0].charAt(0),hand[1].charAt(0))) {
          out.println("YES"); } else {
          out.println("NO"); }
        }
 }

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JavaApplication2 {

    public static void main(String[] args) throws IOException {
        BufferedReader I = new BufferedReader(new InputStreamReader(System.in));
        String s = I.readLine();
        String st[] = I.readLine().split(" ");
        int x;
        if (st[0].contains(s) && !st[1].contains(s)) {
            System.out.println("YES");
        } else if (st[1].contains(s)&&!st[0].contains(s)) {
            System.out.println("NO");
        } else if (a(st[0].charAt(0)) > a(st[1].charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

    static int a(char s) {
        switch (s) {
            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 14;

        }
        return 0;
    }
}

import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;
public class JavaApplication13 {
    public static void main(String[] args) {
    Scanner in=new Scanner(System.in);
    char trump=in.next().charAt(0);
    char []x={'6','7','8','9','T','J','Q','K','A'};
    String a=in.next();
    String b=in.next();
    int a1=0;
    int b1=0;
    if (a.charAt(1)==trump && b.charAt(1)!=trump)
    {
        System.out.print("YES");
    }
    else if(a.charAt(1)!=trump && b.charAt(1)==trump)
    {
        System.out.print("NO");
    }

    else
    {
        for (int i=0;i<x.length;i++)
        {
            if (a.charAt(0)==x[i])
            {
                a1=i;
            }
            if (b.charAt(0)==x[i])
            {
                b1=i;
            }
        }
        System.out.print(a1>b1? "YES":"NO");
    }
    }
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		char trump=sc.next().charAt(0);
		HashMap<Character,Integer> m=new HashMap<>();
		m.put('6',1);
		m.put('7',2);
		m.put('8',3);
		m.put('9',4);
		m.put('T',5);
	    m.put('J',6);
	    m.put('Q',7);
	   	m.put('K',9);
	   	m.put('A',10);
boolean beat=false;
String s1=sc.next();
String s2=sc.next();

if(s1.charAt(1)==trump)
{
	if(s1.charAt(1)!=trump||s1.charAt(1)==trump && (m.get(s1.charAt(0))>m.get(s2.charAt(0))))
	beat=true;
	else
	beat=false;
}

else if(s1.charAt(1)==trump)
beat=false;

else if(s1.charAt(1)==s2.charAt(1) &&  (m.get(s1.charAt(0))>m.get(s2.charAt(0))))
beat=true;
else
beat=false;

if(beat)
System.out.println("YES");
else
System.out.println("NO");

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author noflaxe
 */
public class Durak {

 public static boolean isHigher(char first, char second)
 {
 char[] n = {'6','7','8','9','T','J','Q','K','A'};
 int firstpos = 15;
 int secondpos = 15;
 int i = 0;
 while (firstpos == 15 || secondpos == 15)
 {
 if (first == n[i]) {
 firstpos = i; }
  if (second == n[i]) {
 secondpos = i; }
  i++;
 }
 if (firstpos > secondpos)
 {
 return true;
 }
 else {
 return false; }

}

 public static void main(String[] args) throws IOException
 {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

        String trump=in.readLine();
        String[] hand = in.readLine().split(" ");
        if ((hand[0].contains(trump)) && (!hand[1].contains(trump))) {
        System.out.println("YES");
        } else if ((!hand[0].contains(trump)) && (hand[1].contains(trump))) {
            System.out.println("NO");
        } else if (isHigher(hand[0].charAt(0),hand[1].charAt(0))) {
          System.out.println("YES"); } else {
          System.out.println("NO"); }
        }
 }

import java.util.Scanner;

public class test {
public static void main(String[] args) {
	String win="SHDC";
	String rank="6789TJQKA";
	Scanner s=new Scanner(System.in);
	String tump=s.next();
	String s1=s.next();
	String s2=s.next();

	if(s1.contains(tump+"")&&(!s2.contains(tump+""))) System.out.println("YES");
	else if(s2.contains(tump+"")&&(!s1.contains(tump+""))) System.out.println("NO");
	else{
		String a=s1.charAt(1)+"";
		String b=s2.charAt(1)+"";
		System.out.println(rank.indexOf(a)!=rank.indexOf(b));
		if (rank.indexOf(a)==rank.indexOf(b)){
	    if(rank.indexOf(s1.charAt(0))>rank.indexOf(s2.charAt(0))) System.out.println("YES");
		else System.out.println("NO");
		}
	}

}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author invisible
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CardGame solver = new CardGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class CardGame {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            char c = in.readLine().charAt(0);
            String s[] = in.readLine().split(" ");
            if (s[0].charAt(0) == c) {
                out.printLine("YES");
                return;
            }
            int a[] = new int[200];// "6", "7", "8", "9", "T", "J", "Q", "K" and "A"
            a['6'] = 1;
            a['7'] = 2;
            a['8'] = 3;
            a['9'] = 4;
            a['T'] = 5;
            a['J'] = 6;
            a['Q'] = 7;
            a['K'] = 8;
            a['A'] = 6;
            out.printLine(a[s[0].charAt(0)] > a[s[1].charAt(0)] ? "YES" : "NO");
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

    }
}

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

public class Main{
  public static void main(String... args)throws IOException{
        Map<Character, Integer> m = new HashMap<Character, Integer>();
        Scanner input = new Scanner (System.in);
        String in = input.next();
        //System.out.println("After conversion: " + in);

        String card1 = input.next() ;
        String  card2 = input.next();

        m.put('T' , 10);
        m.put('J' , 11);
        m.put('Q' , 12);
        m.put('K' , 13);
        m.put('A' , 14);
        boolean same = card1.charAt(1)==card2.charAt(1);
        char c1 = card1.charAt(1);
        char c2 = card2.charAt(1);
        char a = in.charAt(0);
        if(c1 == a&& c2!=a)
            System.out.println("YES");
        else if(c2 == a&& c1!=a)
            System.out.println("NO");
            else{
        //System.out.println("After conversion: " + c1);
        if(same){
int c;
char charInt=card1.charAt(0);
if(charInt>=48 && charInt<=57){
    //System.out.println("not character");
    c = card1.charAt(0) - '0';
}
else{

     c = m.get(charInt);
}
    //System.out.println(c);

int c3;
char charInt2=card2.charAt(0);
//System.out.println("not character" + charInt);
if(charInt2>=48 && charInt2<=57){

    c3 = card2.charAt(0) - '0';
}
else{
   // System.out.println("Character");
     c3 = m.get(charInt2);
}
            //System.out.println(c3);
    if(c > c3)
        System.out.println("YES");
    else
        System.out.println("NO");
    }
            }
        System.out.println("NO");

    }
}

import java.util.Scanner;

/**
 *
 * @author Muhammad.Bahaa
 */
public class ACardGame {

    public static void main(String[] args) {
        char cards[] = {'S', 'H', 'D', 'C'};
        char symbol[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
        String trump, card1, card2;
        Scanner in = new Scanner(System.in);
        trump = in.next();
        card1 = in.next();
        card2 = in.next();

        if (card1.contains(trump) && !card2.contains(trump)) {
            System.out.println("YES");
        } else if (card2.contains(trump)&& !card1.contains(trump)) {
            System.out.println("NO");
        } else if (new String(symbol).indexOf(card1.charAt(0)) > new String(symbol).indexOf(card2.charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

import java.util.Scanner;
public class Durak
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String Kozupb = in.next();
        String []data = new String[2];
        char [] data_one = new char[2];
        char [] data_two = new char[2];
        char []inf = new char[]{'6','7','8','9','T','J','Q','K','A'};
        for (int i = 0; i < data.length; i++)
        {
            data[i] = in.next();
        }
        data_one = data[0].toCharArray();
        data_two = data[1].toCharArray();
        int sch_one = 0;
        int sch_two = 0;
        for (int i = 0; i < inf.length; i++)
        {
            if(data_one[0]!=inf[i])
            {
                sch_one++;
            }
            else
            {
                break;
            }
        }
        for (int i = 0; i < inf.length; i++)
        {
            if(data_two[0]!=inf[i])
            {
                sch_two++;
            }
            else
            {
                break;
            }
        }
        if(data_one[1]==data_two[1])
        {
            if(sch_one>sch_two)
            {
                System.out.print("YES");
            }
            else
            {
                System.out.println("NO");
            }
        }
        char a[] = Kozupb.toCharArray();
        boolean flag = true;
        if(data_one[1]!=data_two[1])
        {
            if(data_one[1]==a[0]&&flag == true)
            {
                System.out.println("YES");
                flag = false;
            }
            if(data_two[1]==a[0]&&flag == true)
            {
                System.out.println("NO");
                flag = false;
            }
            if(sch_one>sch_two&&flag == true)
            {
                System.out.print("YES");
            }
            if(sch_one<sch_two&&flag == true)
            {
                System.out.print("NO");
            }

        }

    }

}

import java.io.*;
import java.util.StringTokenizer;

public class B82 {

    private void solve() throws IOException {

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

        char n = nextToken().charAt(0);

        String x = nextToken();
        String y = nextToken();

        char d = x.charAt(1);
        int d1 = 0;

        char f = y.charAt(1);
        int f1 = 0;
        for (int i = 0; i < a.length; i++) {
            if (d == a[i]) {
                d1 = i;
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (f == a[i]) {
                f1 = i;
                break;
            }
        }

        if (x.charAt(1) == n&& y.charAt(1) == n) {
            if (d1 < f1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
        else if (x.charAt(1) == n) {
                System.out.println("YES");
        }
        else if (x.charAt(1) == y.charAt(1)) {
            if (d1 < f1)
                System.out.println("YES");
            else
                System.out.println("NO");

        } else
            System.out.println("NO");
    }

    public static void main(String[] args) {

        new B82().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}

import java.io.*;
import java.util.*;
public class CardGame
{

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
         String  s = in.next();
        String  s1 = in.next();
        String  s2 = in.next();

        char A[]={'6','7','8','9','T', 'J', 'Q', 'K' ,'A'};
        char AA[]={'S', 'H', 'D' , 'C'};

        int n1=0;
        int n2=0;
        int n3=0;
        int n4=0;
        for (int i = 0; i < A.length; i++)
        {
            if (s1.charAt(0)==A[i])
            {
                n1=i;
            }
            if (s2.charAt(0)==A[i])
            {
                n3=i;
            }
        }
         for (int i = 0; i < AA.length; i++)
        {
            if (s1.charAt(1)==AA[i])
            {
                n2=i;
            }
            if (s2.charAt(1)==AA[i])
            {
                n4=i;
            }
        }

         if (n1>n3 && n2 >n4)
         {
             System.out.println("YES");
         }
         else
         {
             System.out.println("NO");
         }
    }

}

import java.util.*;

public class fool {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char k = sc.nextLine().charAt(0);
		String s = sc.nextLine();
		char d1 = s.charAt(0);
		if (d1 == 'T') d1 = 0; else
		if (d1 == 'J') d1 = 1; else
		if (d1 == 'Q') d1 = 2; else
		if (d1 == 'K') d1 = 3; else
			d1 = 4;
		char m1 = s.charAt(1);
		char d2 = s.charAt(3);
		if (d2 == 'T') d2 = 0; else
		if (d2 == 'J') d2 = 1; else
		if (d2 == 'Q') d2 = 2; else
		if (d2 == 'K') d2 = 3; else
			d2 = 4;
		char m2 = s.charAt(4);
		if (m1 == m2) {
			if (d1 > d2) {
				System.out.print("YES");
			} else {
				System.out.print("NO");
			}
		} else {
			if (m1 == k) {
				System.out.print("YES");
			} else {
				System.out.print("NO");
			}
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CardGame {

	public static int transilate(char c) {
		switch (c) {
		case '6':
			return 1;
		case '7':
			return 2;
		case '8':
			return 3;
		case '9':
			return 4;
		case 'T':
			return 5;
		case 'J':
			return 6;
		case 'Q':
			return 7;
		case 'K':
			return 8;
		case 'A':
			return 9;

		}
		return 0;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		char trump = bf.readLine().charAt(0);
		String cards = bf.readLine();
		if (trump != cards.charAt(1) && cards.charAt(1) == cards.charAt(4)
				&& transilate(cards.charAt(0)) > transilate(cards.charAt(3))) {
			System.out.println("YES");
		} else if(trump == cards.charAt(1) &&trump != cards.charAt(4)
				) {
			System.out.println("YES");
		}else
			System.out.println("NO");
	}

}

import java.util.*;
// warm-up
public class CardGame {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String rank = "6789TJQKA";
		char Trump = sc.next().charAt(0); // "Special" character with caps T
		boolean ok = false;
		char[] f = sc.next().toCharArray();
		char[] s = sc.next().toCharArray();
		if((f[1]==Trump)||(f[1]==s[1] && rank.indexOf(f[0])>rank.indexOf(s[0]))) ok = true;
		System.out.println(ok ? "YES" : "NO");
		sc.close();
	}

	public static void main(String args[]) {
		solve();
	}

}

import java.util.Scanner;

public class A76 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.nextLine();
		String s2 = sc.nextLine();
		char c;
		c = s1.charAt(0);
		char c1 = s2.charAt(0);
		char c2 = s2.charAt(3);
		char c3 = s2.charAt(1);
		char c4 = s2.charAt(4);
		if (c1 == 'T'){
			c1 = 10;
		}
		else{
			if (c1 == 'J'){
				c1 = 11;
			}
			else{
				if (c1 == 'Q'){
					c1 = 12;
				}
				else{
					if (c1 == 'K'){
						c1 = 13;
					}
					else{
						if (c1 == 'A'){
							c1 = 14;
						}
					}
				}
			}
		}

		if (c2 == 'T'){
			c2 = 10;
		}
		else{
			if (c2 == 'J'){
				c2 = 11;
			}
			else{
				if (c2 == 'Q'){
					c2 = 12;
				}
				else{
					if (c2 == 'K'){
						c2 = 13;
					}
					else{
						if (c2 == 'A'){
							c2 = 14;
						}
					}
				}
			}
		}
		if (c3 == c4){
			if (c1 > c2){
				System.out.println("YES");
			}
			else{
				System.out.println("NO");
			}
		}
		else{
			if (c3 == c){
				System.out.println("NO");
			}
			else{
				System.out.println("NO");
			}
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class P106A {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}

	static class Task {
		public void solve(InputReader in, PrintWriter out) {
			String tr = in.next();
			String c1 = in.next();
			String c2 = in.next();
			boolean b1 = c1.contains(tr);
			boolean b2 = c2.contains(tr);
			char[] val = new char[] { '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
			if (b1 && !b2)
				out.println("YES");
			else if (!b1 && b2)
				out.println("NO");
			else {
				int val1 = 0;
				while (val[val1] != c1.charAt(0))
					val1++;

				int val2 = 0;
				while (val[val2] != c2.charAt(0))
					val2++;

				if (val1 > val2)
					out.println("YES");
				else
					out.println("NO");
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

	}
}

import java.util.*;
public class Dyrak {

	/**
	 * @param args
	 */
	Scanner sc;
	String res = "NO";
	Dyrak() {
		go();
	}
	public void go() {
		sc = new Scanner(System.in);
		String base = sc.nextLine();
		String hod = sc.nextLine();
		String fmast = hod.charAt(1) + "";
		String fcifra = hod.charAt(0) + "";
		String smast = hod.charAt(4) + "";
		String scifra = hod.charAt(3) + "";

		if ((fmast.equals(base)) & (!smast.equals(base))) {
			res = "YES";
		}
		if (!smast.equals(base)) {
			switch (fcifra){
				case "A":
					res = "YES";
					break;
				case "K":
					if (!scifra.equals("A")) {
						res = "YES";
					}
					break;
				case "Q":
					if ((!scifra.equals("A")) & (!scifra.equals("K"))) {
						res = "YES";
					}
					break;
				case "J":
					if ((!scifra.equals("A")) & (!scifra.equals("K")) & (!scifra.equals("Q"))) {
						res = "YES";
					}
					break;
				case "T":
					if ((!scifra.equals("A")) & (!scifra.equals("K")) & (!scifra.equals("Q")) & (!scifra.equals("J"))) {
						res = "YES";
					}
					break;
				default:
					if ((!scifra.equals("A")) & (!scifra.equals("K")) & (!scifra.equals("Q")) & (!scifra.equals("J")) & (!scifra.equals("T")))
						{
						if ((Integer.parseInt(fcifra) > Integer.parseInt(scifra)) & (fmast.equals(smast))) {
							res ="YES";
						}
					}
			}
		}
		System.out.println(res);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Dyrak();
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class one {
    public static void main(String[] args) throws IOException {
        BufferedReader buf = new BufferedReader(
                new InputStreamReader(System.in));
        HashMap<Character, Integer> map = new HashMap<Character, Integer>();
        map.put('6', 1);
        map.put('7', 2);
        map.put('8', 3);
        map.put('9', 4);
        map.put('T', 5);
        map.put('J', 6);
        map.put('Q', 7);
        map.put('K', 8);
        map.put('A', 9);
        char c = buf.readLine().charAt(0);
        String[] line = buf.readLine().split(" ");
        if (line[0].charAt(1) == c)
            System.out.println("YES");
        else {
            int x = map.get(line[0].charAt(0));
            int y = map.get(line[1].charAt(0));
            if (x > y && line[0].charAt(1) == line[1].charAt(1))
                System.out.println("YES");
            else
                System.out.println("NO");
        }

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(
            System.in));

    public static int toInt(String str) {
        return Integer.parseInt(str);
    }

    public static String toString(int x) {
        return String.valueOf(x);
    }

    public static boolean isVowel(char ch) {
        return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
    }

    public static void main(String[] args) throws IOException {
        String s = reader.readLine();
        char t = s.charAt(0);

        String[] str = reader.readLine().split(" ");

        String a = str[0], b = str[1];

        if (a.charAt(1) == t && b.charAt(1) != t) {
            System.out.println("YES");
            return;
        }

        if (a.charAt(1) != t && b.charAt(1) == t) {
            System.out.println("NO");
            return;
        }
        // "6", "7", "8", "9", "T", "J", "Q", "K" and "A"

        Map<Character, Integer> m = new HashMap<Character, Integer>();
        m.put('6', 1);
        m.put('7', 2);
        m.put('8', 3);
        m.put('9', 4);
        m.put('T', 5);
        m.put('J', 6);
        m.put('Q', 7);
        m.put('K', 8);
        m.put('A', 9);

        if(m.get(a.charAt(0)) > m.get(b.charAt(0))){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

import java.util.Scanner;

public class A106 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char trum = in.next().toCharArray()[0];
		String first = in.next();
		String second = in.next();
		if (first.charAt(1) == second.charAt(1)) {
			System.out.println(first.charAt(0) > second.charAt(0) ? "YES"
					: "NO");
		}

		else if (first.charAt(1) == trum) {

			System.out.println("YES");

		} else  {
			System.out.println("NO");
		}
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static int value(char c) {
        if (c == 'A') {
            return 14;
        } else if (c == 'K') {
            return 13;
        } else if (c == 'Q') {
            return 12;
        } else if (c == 'J') {
            return 11;
        }  else if (c == 'T') {
            return 10;
        } else {
            return Integer.parseInt(Character.toString(c));
        }
    }

    private void solve() throws IOException {
        String trump = nextToken(), first = nextToken(), second = nextToken();
        if (first.charAt(1) == trump.charAt(0) && second.charAt(1) == trump.charAt(0)) {
            if (value(second.charAt(0)) >= value(first.charAt(0))) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        } else if (first.charAt(1) != trump.charAt(0) && second.charAt(1) == trump.charAt(0)) {
            System.out.println("NO");
        } else if (first.charAt(1) == trump.charAt(0) && second.charAt(1) != trump.charAt(0)) {
            System.out.println("YES");
        } else {
            if (value(second.charAt(0)) >= value(first.charAt(0))) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
    }

    public static void main(String[] args) {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            new Main().solve();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(239);
        }
    }
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    static String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

import java.util.*;
import java.io.*;

public class Prb47 {

    static FastReader sc = new FastReader();

    public static void main(String[] args) {

        Map<Character,Integer> map = new HashMap<>();

        map.put('6', 1);
        map.put('7', 2);
        map.put('8', 3);
        map.put('9', 4);
        map.put('T', 5);
        map.put('J', 6);
        map.put('Q', 7);
        map.put('K', 8);
        map.put('A', 9);

        char c = sc.next().charAt(0);
        String s = sc.nextLine();
        if(s.charAt(1) == c){
            System.out.println("YES");
        }else if(map.get(s.charAt(0)) >= map.get(s.charAt(3))){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}

import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import static java.lang.System.*;
import java.math.BigInteger;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;

public class durakGame {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static Scanner sc = new Scanner(System.in);

    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            String temp[] = br.readLine().split(" ");
            Integer temp2[] = new Integer[temp.length];
            for (int i = 0; i < temp.length; i++) {
                temp2[i] = Integer.parseInt(temp[i]);
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static int getMax(Integer[] ar) {
        int t = ar[0];
        for (int i = 0; i < ar.length; i++) {
            if (ar[i] > t) {
                t = ar[i];
            }
        }
        return t;
    }

    public static void printList(List<Integer> a) {
        System.out.println(a.toString().replace("[", "").replace("]", "").replace(",", ""));
    }

    public static void print(Object a) {
        out.println(a);
    }

    public static int nextInt() {
        return sc.nextInt();
    }

    public static double nextDouble() {
        return sc.nextDouble();
    }

    public static BigInteger getFact(long in) {
        BigInteger ot = new BigInteger("1");
        for (Integer i = 1; i <= in; i++) {
            ot = ot.multiply(new BigInteger(i.toString()));
        }
        return ot;
    }

    public static String gbase(int a, int base) {
        String out = "";
        int temp = a;
        while (temp > 0) {
            out = temp % base + out;
            temp /= base;
        }
        return out;
    }

    public static void main(String[] ar) {
        String input = getString();
        String input2[]=getString().split(" ");
        char []rank={'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};

        if(input2[0].charAt(1) == input.toCharArray()[0]){
            print("YES");
            return;
        }
        if(input2[0].charAt(1) != input2[1].charAt(1)){
            print("NO");
            return;
        }
        char my=input2[0].charAt(0);
        int index1=0;
        int index2=0;
        for(int i=0;i<rank.length;i++){
            if(rank[i]==my){
                index1=i;
                break;
            }
        }
        my = input2[1].charAt(0);
        for(int i=0;i<rank.length;i++){
            if(rank[i]==my){
                index2=i;
                break;
            }
        }
        if(index1>index2){
            print("YES");
            return;
        }else{
            print("NO");
            return;
        }

    }
}

import java.util.Scanner;

public class qwr {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
	String s=sc.nextLine();
	char ch=s.charAt(0);
	String sw=sc.nextLine();
	String o=sw.split(" ")[0],t=sw.split(" ")[1],m="6789TJQKA";
	int l=0,k=0;
	if(t.charAt(1)==ch)
	{
		int u;
		for(u=0;u<m.length();u++)
		{
			if(m.charAt(u)==t.charAt(0))
			{
				l++;
				break;
			}
			if(m.charAt(u)==o.charAt(0))
			{
				k++;
				break;
			}
		}
		if(l==1)
		{
			System.out.println("YES");
		}
		if(k==1)
		{
			System.out.println("NO");
		}

	}

	else
	{
		if(o.charAt(1)==ch)
		{
			System.out.println("YES");

		}
		else
		{
			if(o.charAt(1)==t.charAt(1))
			{
				int u;
				for(u=0;u<m.length();u++)
				{
					if(m.charAt(u)==t.charAt(0))
					{
						l++;
						break;
					}
					if(m.charAt(u)==o.charAt(0))
					{
						k++;
						break;
					}
				}
				if(l==1)
				{
					System.out.println("YES");
				}
				if(k==1)
				{
					System.out.println("NO");
				}
			}
			else
				System.out.println("NO");
		}
	}

	}
}

import java.io.*;
import java.util.*;

public class CardGame
{

	public static void main(String args[])
	{

		FastReader sc= new FastReader();
		PrintWriter out = new PrintWriter(System.out);

		int i;
		String first,second;
		char rank[]= {'6','7','8','9','T','J','Q','K','A'};

		char tramp=sc.nextLine().charAt(0);
		String s=sc.nextLine();
		first=s.substring(0,2);
		second=s.substring(3,5);

		if(first.charAt(1)==tramp && second.charAt(1)==tramp) {
			char m=first.charAt(0);
			char p=second.charAt(0);
			int rankf=0,ranks=0;
			for(i=0;i<rank.length;i++) {
				if(rank[i]==m)
					rankf=i;
				if(rank[i]==p)
					ranks=i;
			}
			if(rankf<ranks)
				out.println("NO");
			else
				out.println("YES");
		}
		if(first.charAt(1)==tramp && second.charAt(1)!=tramp)
			out.println("YES");

		if(first.charAt(1)!=tramp && second.charAt(1)==tramp)
			out.println("NO");

		if(first.charAt(1)!=tramp && second.charAt(1)!=tramp) {
			char m=first.charAt(0);
			char p=second.charAt(0);
			int rankf=0,ranks=0;
			for(i=0;i<rank.length;i++) {
				if(rank[i]==m)
					rankf=i;
				if(rank[i]==p)
					ranks=i;
			}
			if(rankf<ranks)
				out.println("NO");
			else
				out.println("YES");
		}
		out.close();
	}

	/*
		FASTREADER
	*/
	static class FastReader
    	{
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }

		/*DEFINED BY ME
		*/
		int[] readArray(int n){

			int arr[]=new int[n];

			for(int i=0;i<n;i++)
				arr[i]=nextInt();

			return arr;
		}
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A106 {
  static FastScanner in;
  static FastWriter out;

  public static void main(String[] args) throws IOException {
    in = new FastScanner(System.in);
    out = new FastWriter(System.out);

    String ts = in.next();
    String f = in.next();
    String s = in.next();

    if (f.contains(ts) == s.contains(ts)) {
      if (power(f) > power(s)) {
        out.println("YES");
      } else {
        out.println("NO");
      }
    } else if (f.contains(ts)) {
      out.println("YES");
    } else {
      out.println("NO");
    }

    out.close();
  }

  static String pow = "6789TJQKA";

  static int power(String s) {
    return pow.indexOf(s.charAt(0));
  }

  static class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(InputStream in) {
      br = new BufferedReader(new InputStreamReader(in));
      st = new StringTokenizer("");
    }

    public FastScanner(File f) throws IOException {
      br = new BufferedReader(new FileReader(f));
      st = new StringTokenizer("");
    }

    public int nextInt() throws IOException {
      return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
      return Long.parseLong(next());
    }

    public double nextDouble() throws IOException {
      return Double.parseDouble(next());
    }

    public String next() throws IOException {
      if (st.hasMoreTokens()) return st.nextToken();
      st = new StringTokenizer(br.readLine());
      return next();
    }
  }

  static class FastWriter extends PrintWriter {
    public FastWriter(OutputStream out) throws IOException {
      super(new BufferedWriter(new OutputStreamWriter(out)));
    }

    public FastWriter(File f) throws IOException {
      super(new BufferedWriter(new FileWriter(f)));
    }
  }
}

import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
public class A {
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		char win = s.charAt(0);
		StringTokenizer st = new StringTokenizer(br.readLine());
		String first = st.nextToken();
		String second = st.nextToken();
		if(first.charAt(1) != second.charAt(1))		{
			if(first.charAt(1) == win)
				System.out.println("YES");
			else
				System.out.println("NO");
			return;
		}
		String order = "6789TDQKA";
		int a = order.indexOf(first.charAt(0)+"");
		int b = order.indexOf(second.charAt(0)+"");
		if(a > b)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

import java.io.*;
import java.util.StringTokenizer;

public class B82 {

    private void solve() throws IOException {

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

        char n = nextToken().charAt(0);

        String x = nextToken();
        String y = nextToken();

        char d = x.charAt(1);
        int d1 = 0;

        char f = y.charAt(1);
        int f1 = 0;
        for (int i = 0; i < a.length; i++) {
            if (d == a[i]) {
                d1 = i;
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (f == a[i]) {
                f1 = i;
                break;
            }
        }

        if (x.charAt(1) == n) {
            if (d1 < f1)
                System.out.println("YES");
            else
                System.out.println("NO");
        } else if (x.charAt(1) == y.charAt(1)) {
            if (d1 < f1)
                System.out.println("YES");
            else
                System.out.println("NO");

        } else
            System.out.println("NO");
    }

    public static void main(String[] args) {

        new B82().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}

import java.io.*;
import java.util.StringTokenizer;

public class B82 {

    private void solve() throws IOException {

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

        char n = nextToken().charAt(0);

        String x = nextToken();
        String y = nextToken();

        char d = x.charAt(1);
        int d1 = 0;

        char f = y.charAt(1);
        int f1 = 0;
        for (int i = 0; i < a.length; i++) {
            if (d == a[i]) {
                d1 = i;
                break;
            }
        }
        for (int i = 0; i < a.length; i++) {
            if (f == a[i]) {
                f1 = i;
                break;
            }
        }

        if (x.charAt(1) == n&& y.charAt(1) == n) {
            if (d1 > f1)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
        else if (x.charAt(1) == n) {
                System.out.println("YES");
        }
        else if (x.charAt(1) == y.charAt(1)) {
            if (d1> f1)
                System.out.println("YES");
            else
                System.out.println("NO");

        } else
            System.out.println("NO");
    }

    public static void main(String[] args) {

        new B82().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}

import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String trump = scan.nextLine();
    String l = scan.nextLine();
    char c1rank = l.charAt(0);
    char c1suit = l.charAt(1);
    char c2rank = l.charAt(3);
    char c2suit = l.charAt(4);
    if (c1suit == trump.charAt(0) && c2suit != trump.charAt(0))
      System.out.println("YES");
    else if (c2suit != c1suit)
      System.out.println("NO");
    else if (c1rank == 'A' && c2rank != 'A')
      System.out.println("YES");
    else if (c1rank == 'K' && c2rank !='A' && c2rank != 'K')
      System.out.println("YES");
    else if (c1rank == 'Q' && c2rank != 'A' && c2rank != 'K' && c2rank !='Q')
      System.out.println("YES");
    else if (c1rank == 'J' && c2rank != 'A' && c2rank != 'K' && c2rank != 'Q' && c2rank != 'J')
      System.out.println("YES");
    else if (c1rank == 'T' && c2rank - '9' <= 0 && c2rank - '6' >= 0)
      System.out.println("YES");
    else if (c1rank > c2rank)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author invisible
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CardGame solver = new CardGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class CardGame {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            char c = in.readLine().charAt(0);
            String s[] = in.readLine().split(" ");

            int a[] = new int[200];// "6", "7", "8", "9", "T", "J", "Q", "K" and "A"
            a['6'] = 1;
            a['7'] = 2;
            a['8'] = 3;
            a['9'] = 4;
            a['T'] = 5;
            a['J'] = 6;
            a['Q'] = 7;
            a['K'] = 8;
            a['A'] = 6;

            if (s[0].charAt(1) == s[1].charAt(1))
                out.printLine(a[s[0].charAt(0)] > a[s[1].charAt(0)] ? "YES" : "NO");
            else {
                out.printLine(s[0].charAt(1) == c ? "YES" : "NO");
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Buffread {
 public static void main(String args[])
 {
   try{
   //  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     Scanner sc =new Scanner(System.in);
    // Set<Double> set = new HashSet<Double>();
     String card = "6789TJQKA";
     String tramp=sc.nextLine();
     String ch = sc.nextLine();
    // System.out.println(card.indexOf(ch.charAt(0)));
    // System.out.println(card.indexOf(ch.charAt(3)));
     if(ch.charAt(1) == tramp.charAt(0) && tramp.charAt(0) == ch.charAt(4))
          if(card.indexOf(ch.charAt(0)) > card.indexOf(ch.charAt(3)))
              System.out.println("YES");
          else
              System.out.println("NO");

     else if(ch.charAt(1) == tramp.charAt(0) && tramp.charAt(0) != ch.charAt(4))
          System.out.println("YES");

     else if(ch.charAt(1) != tramp.charAt(0) && tramp.charAt(0) != ch.charAt(4))
         if(card.indexOf(ch.charAt(0)) > card.indexOf(ch.charAt(3)))
                System.out.println("YES");
         else
             System.out.println("NO");
     else if(ch.charAt(1) != tramp.charAt(0) && tramp.charAt(0) == ch.charAt(4))
         System.out.println("NO");

     sc.close();
   } // End Of Try Block

    catch(Exception e) {
        e.printStackTrace();
    }
 } // End Of Main Block
}

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;

        public void run() {
            char t = sc.next().charAt(0);
            char[] a = sc.next().toCharArray();
            char[] b = sc.next().toCharArray();
            int[] word = new int[256];
            int i = 0;
            word['6'] = i++; word['7'] = i++; word['8'] = i++; word['9'] = i++;
            word['T'] = i++; word['J'] = i++; word['Q'] = i++; word['K'] = i++; word['A'] = i++;
            int win = 0;
            if (a[1] == t) {
                if (b[1] != t) win = 0;
                else if (word[a[0]] < word[b[0]]) win = 1;
                else win = 0;
            }
            else if (a[1] == b[1]) {
                if (word[a[0]] < word[b[0]]) {
                    win = 0;
                }
            }
            else {
                win = 1;
            }
            System.out.println(win == 0 ? "YES" : "NO");
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}

import java.io.*;
import java.util.*;
public class A {
    public static void main(String args[])
        throws IOException {
        Scanner sc = new Scanner(System.in);
        String trump = sc.next();
        String first = sc.next();
        String second = sc.next();
        String rank[] = { "6", "7", "8", "9", "T", "J", "Q", "K", "A"};
        Map<String, Integer> map = new HashMap<String, Integer> ();
        for(int i = 0; i< 9; i++)
            map.put(rank[i], i);
        boolean flag = false;
        if(first.substring(1,2).equals(second.substring(1,2))) {
            if(map.get(first.substring(0,1)) > map.get(second.substring(0,1)))
                flag = true;
            else
                flag = false;
        } else {
            if(trump.equals(first.substring(1,2)))
                flag = true;
            else {
                if(map.get(first.substring(0,1)) > map.get(second.substring(0,1)))
                    flag = true;
                else
                    flag = false;
            }
        }
        if(flag) System.out.println("YES");
        else System.out.println("NO");
    }
}

import java.io.*;
import java.math.*;
import java.util.*;

public class A {

	public static void main(String[] agrs) {
		FastScanner sc = new FastScanner();
//		int yo = sc.nextInt();
//		while(yo-->0) {

//		}

		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();

		List<String> list = new ArrayList<>();
		list.add("6");list.add("7");list.add("8");list.add("9");list.add("T");
		list.add("J");list.add("Q");list.add("K");list.add("A");

		List<String> list2 = new ArrayList<>();
		list2.add("S");list2.add("H");list2.add("D");list2.add("C");

		if(!(s3.charAt(1)+"").equals(s1) && (s2.charAt(1)+"").equals(s1)) {
			System.out.println("YES");
		}
		else if(!(s2.charAt(1)+"").equals(s1) && (s3.charAt(1)+"").equals(s1)) {
			System.out.println("NO");
		}
		else {
			if(list.indexOf(s2.charAt(0)) > list.indexOf(s3.charAt(0))) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
	}

	static int mod = 1000000007;
	static long pow(int a, int b) {
		if(b == 0) {
			return 1;
		}
		if(b == 1) {
			return a;
		}
		if(b%2 == 0) {
			long ans = pow(a,b/2);
			return ans*ans;
		}
		else {
			long ans = pow(a,(b-1)/2);
			return a * ans * ans;
		}

	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}

import java.awt.Point;
import java.io.*;
import java.util.*;

import javax.swing.*;
public class Xtend {
public static void main(String[] args)throws IOException{
	Scanner input=new Scanner(System.in);
	String trump=input.next();
	String first=input.next();
	String second=input.next();
	if(trump.charAt(0)==first.charAt(1) && first.charAt(1)!=second.charAt(1)){
		System.out.println("YES");
	}else if(trump.charAt(0)!=first.charAt(1) && first.charAt(1)==second.charAt(1)){
		if(Character.isLetter(first.charAt(0)) && Character.isDigit(second.charAt(0))){
			System.out.println("YES");
		}else if(Character.isDigit(first.charAt(0)) && Character.isDigit(second.charAt(0)) && first.charAt(0)>second.charAt(0)){
			System.out.println("YES");
		}else if(Character.isLetter(first.charAt(0)) && Character.isLetter(second.charAt(0)) && second.charAt(0)=='T'){
			System.out.println("YES");
		}else if(Character.isLetter(first.charAt(0)) && Character.isLetter(second.charAt(0)) && first.charAt(0)=='A'){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}else if(trump.charAt(0)==first.charAt(1) && first.charAt(1)==second.charAt(1)){
		if(Character.isLetter(first.charAt(0)) && Character.isDigit(second.charAt(0))){
			System.out.println("YES");
		}else if(Character.isDigit(first.charAt(0)) && Character.isDigit(second.charAt(0)) && first.charAt(0)>second.charAt(0)){
			System.out.println("YES");
		}else if(Character.isLetter(first.charAt(0)) && Character.isLetter(second.charAt(0)) && first.charAt(0)=='A'){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}

	else{
		System.out.println("NO");
	}
}
}

import java.io.*;
import java.util.*;

public class Main implements Runnable
{
	void solve() throws IOException
    {
		//while(sc.hasNext()){
		String ans="NO";
    	char t = sc.next().charAt(0);
    	String s = sc.next();
    	char s1 = s.charAt(1);
    	char r1 = s.charAt(0);
    	s = sc.next();
    	char s2 = s.charAt(1);
    	char r2 = s.charAt(0);
    	int rr1,rr2;
    	if(r1=='T') rr1=10;
    	else if (r1=='J') rr1=11;
    	else if (r1=='Q') rr1=12;
    	else if (r1=='K') rr1=13;
    	else if (r1=='A') rr1=14;
    	else
    		rr1 = Integer.parseInt(r1+"");
    	if(r2=='T') rr2=10;
    	else if (r2=='J') rr2=11;
    	else if (r2=='Q') rr2=12;
    	else if (r2=='K') rr2=13;
    	else if (r2=='A') rr2=14;
    	else
    		rr2 = Integer.parseInt(r2+"");
    	if(s1==s2&&rr1>rr2)
    		ans = "YES";
    	else if(s1==t)
    		ans = "YES";
    	ps.println(ans);
    	//}

    }

	Scanner sc;
	PrintStream ps;

    public void run()
    {
		try
		{
			sc = new Scanner(System.in);
			//sc = new Scanner(new File("a.in"));
			ps = new PrintStream(System.out);
			solve();
			sc.close();
			ps.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
			System.exit(0);
		}
    }

    public static void main(String[] args)
    {
		new Thread(new Main()).start();
    }
}

import java.util.Scanner;

/**
 *
 * @author Muhammad.Bahaa
 */
public class ACardGame {

    public static void main(String[] args) {
        char cards[] = {'S', 'H', 'D', 'C'};
        char symbol[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
        String trump, card1, card2;
        Scanner in = new Scanner(System.in);
        trump = in.next();
        card1 = in.next();
        card2 = in.next();

        if (card1.contains(trump) && !card2.contains(trump)) {
            System.out.println("YES");
        } else if (card2.contains(trump)&& !card1.contains(trump)) {
            System.out.println("NO");
        } else if (new String(symbol).indexOf(card1.charAt(0)) > new String(symbol).indexOf(card2.charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

import java.util.Scanner;

public class copy {
       private String name = "Fluffy";

       public static void main(String[] args) {
              String trupmSuite, firstCard, secondCard, firstChar, secondChar;

              char[] Suites = { 'S', 'H', 'D', 'C' };
              char[] Rank = { '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
              Scanner input = new Scanner(System.in);
              int first = 0;
              int sec = 0;
              trupmSuite = input.next();
              firstCard = input.next();
              secondCard = input.next();

              if (firstCard.substring(0, 1).equals("T"))
                     first = 10;
              else if (firstCard.substring(0, 1).equals("J"))
                     first = 11;
              else if (firstCard.substring(0, 1).equals("Q"))
                     first = 12;
              else if (firstCard.substring(0, 1).equals("K"))
                     first = 13;
              else if (firstCard.substring(0, 1).equals("A"))
                     first = 14;
              else {
                     first = Integer.parseInt(firstCard.substring(0, 1));
              }

              if (secondCard.substring(0, 1).equals("T"))
                     sec = 10;
              else if (secondCard.substring(0, 1).equals("J"))
                     sec = 11;
              else if (secondCard.substring(0, 1).equals("Q"))
                     sec = 12;
              else if (secondCard.substring(0, 1).equals("K"))
                     sec = 13;
              else if (secondCard.substring(0, 1).equals("A"))
                     sec = 14;
              else {
                     sec = Integer.parseInt(secondCard.substring(0, 1));
              }

              if (firstCard.contains(trupmSuite) && secondCard.contains(trupmSuite)) { // Case
                                                                                // 1

                     if (first > sec)
                           System.out.println("YES");

                     else
                           System.out.println("NO");
              } else if (firstCard.contains(trupmSuite) && !secondCard.contains(trupmSuite)) // Case
                                                                                // 2
                     System.out.println("YES");
              else if (!firstCard.contains(trupmSuite) && secondCard.contains(trupmSuite)) // Case
                                                                                // 3
                     System.out.println("NO");
              else if (!firstCard.contains(trupmSuite) && !secondCard.contains(trupmSuite)) {
                     if (first > sec)
                           System.out.println("YES");

                     else
                           System.out.println("NO");

              } else
                     System.out.println("NO");

       }
}

import java.util.HashMap;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Karim
 */
public class CardGame {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);
        String trump = r.next();
        String firstCard = r.next();
        String secondCard = r.next();
        String firstR = "" + firstCard.charAt(0);
        String firstT = "" + firstCard.charAt(1);
        String secondR = "" + secondCard.charAt(0);
        String secondT = "" + secondCard.charAt(1);
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        map.put("6", 1);
        map.put("7", 2);
        map.put("8", 3);
        map.put("9", 4);
        map.put("T", 5);
        map.put("J", 6);
        map.put("Q", 7);
        map.put("K", 8);
        map.put("A", 9);
        if (firstT.equals(trump)) {
            if (secondT.equals(trump)) {
                // compare digits
                // "6", "7", "8", "9", "T", "J", "Q", "K" and "A"
                if (map.get(firstR) > map.get(secondR)) {
                    System.out.println("YES");
                    System.exit(0);
                } else {
                    System.out.println("NO");
                    System.exit(0);
                }
            } else {
                System.out.println("YES");
                System.exit(0);
            }
        } else if (secondT.equals(trump)) {
            System.out.println("NO");
            System.exit(0);
        } else {
//            if (map.get(firstR) > map.get(secondR)) {
//                System.out.println("YES");
//                System.exit(0);
//            } else {
//                System.out.println("NO");
//                System.exit(0);
//            }
            System.out.println("NO");
            System.exit(0);
        }
    }
}

import java.util.Scanner;

public class A106 {
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		String stroka = in.nextLine(), k1 = in.next(), k2 = in.next();

		char s = stroka.charAt(0);

		if (s == k1.charAt(1)) {
			System.out.println("YES");
			return;
		}

		if (k1.charAt(1) != k2.charAt(1)) {
			System.out.println("NO");
		}

		char q = k1.charAt(0), w = k2.charAt(0);

		int q1, w1;

		if (q == 'T')
			q1 = 10;
		else if (q == 'J')
			q1 = 11;
		else if (q == 'Q')
			q1 = 12;
		else if (q == 'K')
			q1 = 13;
		else if (q == 'A')
			q1 = 14;
		else
			q1 = Integer.parseInt(k1.substring(0, 1));

		if (w == 'T')
			w1 = 10;
		else if (w == 'J')
			w1 = 11;
		else if (w == 'Q')
			w1 = 12;
		else if (w == 'K')
			w1 = 13;
		else if (w == 'A')
			w1 = 14;
		else
			w1 = Integer.parseInt(k2.substring(0, 1));

		if (q1 > w1)
			System.out.println("YES");
		else
			System.out.println("NO");

	}
}

import java.util.*;
// warm-up
public class CardGame {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String rank = "6789TJQKA";
		char Trump = sc.next().charAt(0); // "Special" character with caps T
		boolean ok = false;
		char[] f = sc.next().toCharArray();
		char[] s = sc.next().toCharArray();
		if((f[1]==Trump)||(f[1]==s[1] && rank.indexOf(f[0])>rank.indexOf(s[0]))) ok = true;
		System.out.println(ok ? "YES" : "NO");
		sc.close();
	}

	public static void main(String args[]) {
		solve();
	}

}

import java.util.Scanner;
public class Durak
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String Kozupb = in.next();
        String []data = new String[2];
        char [] data_one = new char[2];
        char [] data_two = new char[2];
        char []inf = new char[]{'6','7','8','9','T','J','Q','K','A'};
        for (int i = 0; i < data.length; i++)
        {
            data[i] = in.next();
        }
        data_one = data[0].toCharArray();
        data_two = data[1].toCharArray();
        int sch_one = 0;
        int sch_two = 0;
        for (int i = 0; i < inf.length; i++)
        {
            if(data_one[0]!=inf[i])
            {
                sch_one++;
            }
            else
            {
                break;
            }
        }
        for (int i = 0; i < inf.length; i++)
        {
            if(data_two[0]!=inf[i])
            {
                sch_two++;
            }
            else
            {
                break;
            }
        }
        if(data_one[1]==data_two[1])
        {
            if(sch_one>sch_two)
            {
                System.out.print("YES");
            }
            else
            {
                System.out.println("NO");
            }
        }
        char a[] = Kozupb.toCharArray();
        if(data_one[1]==a[0])
        {
            if(data_two[1]!=a[0])
            {
                System.out.println("YES");
            }
        }
        if(data_one[1]!=a[0])
        {
            if(data_two[1]==a[0])
            {
                System.out.println("NO");
            }
        }
        if(data_one[1]!=a[0] && data_two[1]!=a[0])
        {
            if(sch_one>sch_two)
            {
                System.out.print("YES");
            }
            else
            {
                System.out.println("NO");
            }
        }

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Created by IntelliJ IDEA.
 * User: tiro
 * Date: 19/08/11
 * Time: 18:00
 * To change this template use File | Settings | File Templates.
 */

public class Durak extends Thread {
    private String doS(String input) {
        if (!Character.isDigit(input.charAt(0))) {
            input = input.replace('T', '4');
            input = input.replace('J', '5');
            input = input.replace('Q', '6');
            input = input.replace('K', '7');
            input = input.replace('A', '8');
        } else {
            Integer digit = Character.digit(input.charAt(0), 10);
            Character ch = digit.toString().charAt(0);
            digit -= 6;
            input = input.replace(ch, new Character(digit.toString().charAt(0)));
        }
        return input;
    }

    public void Run() {
        try {
            String superType = nextToken();
            String first = nextToken();
            String second = nextToken();
            first = doS(first);
            second = doS(second);
            if (first.charAt(1) == second.charAt(1) && Character.digit(first.charAt(0), 10) > Character.digit(second.charAt(0), 10)) {
                out.print("YES");
                return;
            } else if (first.charAt(1) == superType.charAt(0)) {
                out.print("YES");
                return;
            }
            out.print("NO");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            out.flush();
            out.close();
        }
    }

    public static void main(String[] args) {
        new Durak().Run();
    }

    public Durak() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        setPriority(Thread.MAX_PRIORITY);
    }

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer stringTokenizer;

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private String nextToken() throws IOException {
        if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
            stringTokenizer = new StringTokenizer(in.readLine(), "\t\n\r ");
        }
        return stringTokenizer.nextToken();
    }
}

import java.util.Scanner;

public class A76 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.nextLine();
		String s2 = sc.nextLine();
		char c;
		c = s1.charAt(0);
		char c1 = s2.charAt(0);
		char c2 = s2.charAt(3);
		char c3 = s2.charAt(1);
		char c4 = s2.charAt(4);
		if (c1 == 'T'){
			c1 = 10;
		}
		else{
			if (c1 == 'J'){
				c1 = 11;
			}
			else{
				if (c1 == 'Q'){
					c1 = 12;
				}
				else{
					if (c1 == 'K'){
						c1 = 13;
					}
					else{
						if (c1 == 'A'){
							c1 = 14;
						}
					}
				}
			}
		}

		if (c2 == 'T'){
			c2 = 10;
		}
		else{
			if (c2 == 'J'){
				c2 = 11;
			}
			else{
				if (c2 == 'Q'){
					c2 = 12;
				}
				else{
					if (c2 == 'K'){
						c2 = 13;
					}
					else{
						if (c2 == 'A'){
							c2 = 14;
						}
					}
				}
			}
		}
		if (c3 == c4){
			if (c1 > c2){
				System.out.println("YES");
			}
			else{
				System.out.println("NO");
			}
		}
		else{
			if (c4 == c){
				System.out.println("NO");
			}
			else{
				System.out.println("NO");
			}
		}
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JavaApplication2 {

    public static void main(String[] args) throws IOException {
        BufferedReader I = new BufferedReader(new InputStreamReader(System.in));
        String s = I.readLine();
        String st[] = I.readLine().split(" ");
        int x;
        if (st[0].contains(s) && !st[1].contains(s)) {
            System.out.println("YES");
        } else if (st[1].contains(s)) {
            System.out.println("NO");
        } else if (a(st[0].charAt(0)) > a(st[1].charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

    static int a(char s) {
        switch (s) {
            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 14;

        }
        return 0;
    }
}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class CardGame {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String c = in.next();
		in.nextLine();
		String first = in.next();
		String second = in.next();

		HashMap<String,Integer> al = new HashMap<String,Integer>();

		al.put("6",1);
		al.put("7",2);
		al.put("8",3);
		al.put("9",4);
		al.put("T",5);
		al.put("J",6);
		al.put("Q",7);
		al.put("K",8);
		al.put("A",9);

		if((first.charAt(1)+"").equals(second.charAt(1)+"")) {
			if(al.get(first.charAt(0)+"") >= al.get(second.charAt(0)+"") )
				System.out.println("YES");
		} else if (c.equals(first.charAt(0)+"")) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}

import java.util.Scanner;

public class MainIter {

    /**
     * @param args
     */
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        String mast;
        mast = scan.next();
        String card1 = scan.next();
        String card2 = scan.next();

        boolean yes = false;

        if (card1.charAt(1) == mast.charAt(0)
                && card2.charAt(1) != mast.charAt(0)) {
            yes = true;
        } else {

            if (card1.charAt(1) == card2.charAt(1)) {

                if (card1.charAt(0) != 'T' && card2.charAt(0) != 'A'
                        && card2.charAt(0) != 'J' && card2.charAt(0) != 'K'
                        && card2.charAt(0) != 'Q') {
                    if (card1.charAt(0) > card2.charAt(0))
                        yes = true;
                } else {
                    if (card1.charAt(0) == 'A') {
                        yes = true;
                    } else {
                        if (card1.charAt(0) == 'K' && card2.charAt(0) != 'A')
                            yes = true;

                        else {

                            if (card1.charAt(0) == 'T'
                                    && card2.charAt(0) != 'A'
                                    && card2.charAt(0) != 'J'
                                    && card2.charAt(0) != 'K'
                                    && card2.charAt(0) != 'Q')
                                yes = true;
                            else {
                                if (card1.charAt(0) == 'J'
                                        && card2.charAt(0) != 'K'
                                        && card2.charAt(0) != 'A'
                                        && card2.charAt(0) != 'Q')
                                    yes = true;
                                else {

                                    if (card1.charAt(0) == 'Q'
                                            && card2.charAt(0) != 'K'
                                            && card2.charAt(0) != 'A')

                                        yes = true;
                                }
                            }
                        }
                    }

                }
            }
        }

        if (yes) {
            System.out.print("YES");
        } else {
            System.out.print("NO");
        }

    }
}

import java.util.*;
public class CardGame {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        Map<Character, Integer> rank = new HashMap<Character, Integer>();
        rank.put('6', 6);
        rank.put('7', 7);
        rank.put('8', 8);
        rank.put('9', 9);
        rank.put('T', 10);
        rank.put('J', 11);
        rank.put('Q', 12);
        rank.put('K', 13);
        rank.put('A', 14);

        String trump = sc.next();
        String s1 = sc.next();
        String s2 = sc.next();;

        boolean flag1 = false;
        for(char c: s1.toCharArray()){
            if(c == trump.charAt(0)){
                flag1 = true;
            }
        }

        boolean flag2 = false;
        for(char c: s2.toCharArray()){
            if(c == trump.charAt(0)){
                flag2 = true;
            }
        }

        if(flag1 && !flag2){
            System.out.println("YES");
        }else{
            int val1 = rank.get(s1.charAt(0));
            int val2 = rank.get(s2.charAt(0));

            if(val1 > val2){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

import java.io.*;
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
        Reader.init(System.in);
        String trump =Reader.next();
        String t1 =Reader.next();
        String t2 =Reader.next();
        int c=0;
        if(trump.charAt(0)==t1.charAt(1)&&t1.charAt(1)!=t2.charAt(1))
        {
            System.out.println("YES");
            return;
        }
        else
        if(trump.charAt(0)==t2.charAt(1)&&t2.charAt(1)!=t1.charAt(1))
        {
            System.out.println("NO");
            return;
        }
        else
        if(Character.isAlphabetic(t1.charAt(0))&&Character.isAlphabetic(t2.charAt(0)))
        {
        if(t1.charAt(0)=='A'&&(t2.charAt(0)=='K'||t2.charAt(0)=='Q'||t2.charAt(0)=='J'||t2.charAt(0)=='T'))
            c=1;
        else
        if(t1.charAt(0)=='K'&&(t2.charAt(0)=='Q'||t2.charAt(0)=='J'||t2.charAt(0)=='T'))
            c=1;
            else

        if(t1.charAt(0)=='Q'&&(t2.charAt(0)=='J'||t2.charAt(0)=='T'))
            c=1;
        else
        if(t1.charAt(0)=='J'&&(t2.charAt(0)=='T'))
            c=1;

        }
        else
        if(Character.isAlphabetic(t1.charAt(0)))
        {
            System.out.println("YES");
            return;
        }
        else

        if(Character.isAlphabetic(t2.charAt(0)))
        {
            System.out.println("NO");
            return;
        }
        else
            if(Integer.valueOf(t1.charAt(0)+"")>Integer.valueOf(t2.charAt(0)+""))
                c=1;

        System.out.println(c==1?"YES":"NO");

  }
}
class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static public void nextIntArrays(int[]... arrays) throws IOException {
        for (int i = 1; i < arrays.length; ++i) {
            if (arrays[i].length != arrays[0].length) {
                throw new InputMismatchException("Lengths are different");
            }
        }
        for (int i = 0; i < arrays[0].length; ++i) {
            for (int[] array : arrays) {
                array[i] = nextInt();
            }
        }
    }

    static public void nextLineArrays(String[]... arrays) throws IOException {
        for (int i = 1; i < arrays.length; ++i) {
            if (arrays[i].length != arrays[0].length) {
                throw new InputMismatchException("Lengths are different");
            }
        }
        for (int i = 0; i < arrays[0].length; ++i) {
            for (String[] array : arrays) {
                array[i] = reader.readLine();
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class CardGame {
	public static void main(String[] args) {
		PrintWriter pw = new PrintWriter(System.out);
	    reader(System.in);
	    char ts = n().charAt(0);
	    String c1 = n();
	    String c2 = n();
	    int cnt1 = 0;
	    int cnt2 = 0;
	    if (c1.charAt(0) == 'A') {
	    	cnt1 = 14;
	    }
	    else if (c1.charAt(0) == 'K') {
	    	cnt1 = 13;
	    }
	    else if (c1.charAt(0) == 'Q') {
	    	cnt1 = 12;
	    }
	    else if (c1.charAt(0) == 'J') {
	    	cnt1 = 11;
	    }
	    else if (c1.charAt(0) == 'T') {
	    	cnt1 = 10;
	    }
	    else {
	    	cnt1 = c1.charAt(0) - '0';
	    }
	    if (c2.charAt(0) == 'A') {
	    	cnt2 = 14;
	    }
	    else if (c2.charAt(0) == 'K') {
	    	cnt2 = 13;
	    }
	    else if (c2.charAt(0) == 'Q') {
	    	cnt2 = 12;
	    }
	    else if (c2.charAt(0) == 'J') {
	    	cnt2 = 11;
	    }
	    else if (c2.charAt(0) == 'T') {
	    	cnt2 = 10;
	    }
	    else {
	    	cnt2 = c2.charAt(0) - '0';
	    }
	    if ((cnt1 > cnt2 && (c1.charAt(1) == ts || c1.charAt(1) == c2.charAt(1))) ||
	    	(cnt1 < cnt2 && c1.charAt(1) == ts && c1.charAt(1) != c2.charAt(1)))
	    	pw.println("YES");
	    else
	    	pw.println("NO");
	    pw.close();
	}

	private static BufferedReader br;
	private static StringTokenizer st;

	static void reader(InputStream stream) {
	    try {
	        br = new BufferedReader(new InputStreamReader(stream));
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}

	static String n() {
	    while (st == null || !st.hasMoreTokens()) {
	        try {
	            st = new StringTokenizer(br.readLine());
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	    }
	    return st.nextToken();
	}

	static int nI() {
	    return Integer.parseInt(n());
	}

	static long nL() {
	    return Long.parseLong(n());
	}
}

import java.util.HashMap;
import java.util.Scanner;

public class CF106A {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        HashMap<Character,Integer> hm=new HashMap<>();
        hm.put('6',1);
        hm.put('7',2);
        hm.put('8',3);
        hm.put('9',4);
        hm.put('T',5);
        hm.put('J',6);
        hm.put('Q',7);
        hm.put('K',8);
        hm.put('A',9);
        String trump=s.nextLine();
        String a=s.next();
        String b=s.next();
        if(a.charAt(1)==trump.charAt(0)){
            System.out.println("YES");
        }
        else{
            if(hm.get(a.charAt(0))>hm.get(b.charAt(0)) && a.charAt(1)==b.charAt(1)){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }

    }
}

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

import com.sun.jndi.url.iiopname.iiopnameURLContextFactory;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String tramp = scanner.next(), first = scanner.next(), second = scanner.next();
        if(tramp.matches(first) && tramp.matches(second)||!tramp.matches(first) && !tramp.matches(second)){
            if(winner(first.charAt(0), second.charAt(0)))
                System.out.println("YES");
            else
                System.out.println("NO");
        }else if (tramp.matches(first) && !tramp.matches(second))
            System.out.println("YES");
        else if (!tramp.matches(first) && tramp.matches(second))
            System.out.println("NO");
    }
    private static boolean winner(char first, char second){
        if(replaceCharacter(first)>replaceCharacter(second))
            return true;
        else
            return false;
    }
    private static int replaceCharacter(char first) {
        if(first=='T')
            return 10;
        else if (first=='J')
            return 11;
        else if (first=='Q')
            return 12;
        else if (first=='K')
            return 13;
        else if (first=='A')
            return 14;
        else return Character.getNumericValue(first);
    }
}

import java.util.*;

import static java.lang.System.out;
import static java.lang.Math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().A();
	}

	void A(){
		HashMap<String,Integer> dic = new HashMap<String,Integer>();
		dic.put("6", 1);	dic.put("7", 2);	dic.put("8", 3);	dic.put("9", 4);	dic.put("T", 5);
		dic.put("J", 6);	dic.put("Q", 7);	dic.put("K", 8);	dic.put("A", 9);
		String m=sc.next(), a=sc.next(), b=sc.next(), ans="NO";
		if(m.equals(""+a.charAt(1)) || m.equals(""+b.charAt(1)))	ans="YES";
		if(a.charAt(1)==b.charAt(1)){
			if(dic.get(""+a.charAt(0))>dic.get(""+b.charAt(0)))	ans="YES";
			else	ans="NO";
		}
		out.println(ans);
	}

}

import java.util.Scanner;
public class game2 {

public static void main (String args[]){

		Scanner scan =new Scanner(System.in);
		String suit []=new String[4];
		suit[0]="S";
		suit[1]="H";
		suit[2]="D";
		suit[3]="C";
		String rank []={"6", "7", "8", "9", "T", "J", "Q", "K" ,"A"};
		String s=new String();
		String p1=new String();
		int x=0;
		int y=0;
		s=scan.nextLine();
		p1=scan.nextLine();
		if(s.charAt(0)==p1.charAt(1))
		{
			System.out.println("YES");
		}

		else
		{
			if(p1.charAt(4)!=p1.charAt(1))
			{
				System.out.println("NO");
			}
			else
			{
			for(int i=0;i<9;i++)
			{
				if(p1.charAt(0)==rank[i].charAt(0))
				{
					x=i;
				}
				if(p1.charAt(3)==rank[i].charAt(0))
				{
					y=i;
				}

			}
			if(x>y)
				System.out.println("YES");
			else
				System.out.println("NO");
			}
		}

	}

}

import java.util.Scanner;

/**
 *
 * @author Muhammad.Bahaa
 */
public class ACardGame {

    public static void main(String[] args) {
        char cards[] = {'S', 'H', 'D', 'C'};
        char symbol[] = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
        String trump, card1, card2;
        Scanner in = new Scanner(System.in);
        trump = in.next();
        card1 = in.next();
        card2 = in.next();

        if (card1.contains(trump) && !card2.contains(trump)) {
            System.out.println("YES");
        } else if (card2.contains(trump)&& !card1.contains(trump)) {
            System.out.println("NO");
        } else if (new String(symbol).indexOf(card1.charAt(0)) > new String(symbol).indexOf(card2.charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

import java.util.Scanner;
import java.math.*;
public class Main {

    public static void main(String[] args) {
         Scanner in=new Scanner(System.in);
         String a, b;
         char trump;

         trump=in.next().charAt(0);
         a=in.next();
         b=in.next();
         if(a.charAt(1)==b.charAt(1)&&a.charAt(0)>b.charAt(0))
             System.out.print("YES");
         else
             if(a.charAt(1)==trump)
             {
                 if(b.charAt(1)==trump)
                 {
                     if(a.charAt(0)>b.charAt(0))
                         System.out.print("YES");
                     else
                         System.out.print("NO");

                 }
                 else
                     System.out.print("YES");

             }
             else
                 System.out.print("NO");

         }

    }

import java.util.Scanner;
public class Durak
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String Kozupb = in.next();
        String []data = new String[2];
        char [] data_one = new char[2];
        char [] data_two = new char[2];
        char []inf = new char[]{'6','7','8','9','T','J','Q','K','A'};
        for (int i = 0; i < data.length; i++)
        {
            data[i] = in.next();
        }
        data_one = data[0].toCharArray();
        data_two = data[1].toCharArray();
        int sch_one = 0;
        int sch_two = 0;
        for (int i = 0; i < inf.length; i++)
        {
            if(data_one[0]!=inf[i])
            {
                sch_one++;
            }
            else
            {
                break;
            }
        }
        for (int i = 0; i < inf.length; i++)
        {
            if(data_two[0]!=inf[i])
            {
                sch_two++;
            }
            else
            {
                break;
            }
        }
        if(data_one[1]==data_two[1])
        {
            if(sch_one>sch_two)
            {
                System.out.print("YES");
            }
            else
            {
                System.out.println("NO");
            }
        }
        char a[] = Kozupb.toCharArray();
        boolean flag = true;
        if(data_one[1]!=data_two[1])
        {
            if(data_one[1]==a[0]&&flag == true)
            {
                System.out.println("YES");
                flag = false;
            }
            if(data_two[1]==a[0]&&flag == true)
            {
                System.out.println("NO");
                flag = false;
            }
            if(sch_one>sch_two&&flag == true)
            {
                System.out.print("YES");
            }
            if(sch_one<sch_two&&flag == true)
            {
                System.out.print("YES");
            }

        }

    }

}

import java.util.Scanner;

/**
 * Created by vinayr on 8/25/17.
 */
public class TrumpCard {
    public static void main(String[] args){
        String s1;
        Scanner sc = new Scanner(System.in);
        s1=sc.next();
        String s2="";
        String s3;
        s2=sc.next();
        s3=sc.next();
        //System.out.println(s1 + " "+s2+ " "+s3);

        String res="6789JQKA";
        if(s2.charAt(1)==s1.charAt(0) && s3.charAt(1)!=s1.charAt(0))
        {
            System.out.println("YES");

        }
        else if(s2.charAt(1)==s3.charAt(1)){
            if(res.indexOf(s2.substring(0,1)) > res.indexOf(s3.substring(0,1))){
                System.out.println("YES");

            }
            else
                System.out.println("NO");
        }
        else
            System.out.println("NO");

    }
}

import java.util.Scanner;

/**
 *
 * @author ONE BY ONE
 */
public class CardGame {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner s= new Scanner (System.in);
       String y=s.next();
       String h=s.next(); String r=s.next();
       if(h.contains(y)&&!(r.contains(y)))
            System.out.println("YES");
       else  if(!(h.contains(y))&&(r.contains(y)))
            System.out.println("NO");
       else  if(!(h.contains(y))&&!(r.contains(y))||((h.contains(y))&&(r.contains(y)))){
           int g=h.charAt(0);
           int v=r.charAt(0);
           if((g>=54&&g<=57) &&(v>=54&&v<=57))
               if(g>v)
                   System.out.println("YES");
           else
                   System.out.println("NO");

           else if((h.charAt(0)=='T'||h.charAt(0)=='Q'||h.charAt(0)=='J'|h.charAt(0)=='A'||h.charAt(0)=='K')&&(v>=54&&v<=57))
               System.out.println("YES");
  else if((r.charAt(0)=='T'||r.charAt(0)=='Q'||r.charAt(0)=='J'|r.charAt(0)=='A'||r.charAt(0)=='K')&&(g>=54&&g<=57))
               System.out.println("NO");

        else if((r.charAt(0)=='T'||r.charAt(0)=='Q'||r.charAt(0)=='J'|r.charAt(0)=='A'||r.charAt(0)=='K')&&(h.charAt(0)=='T'||h.charAt(0)=='Q'||h.charAt(0)=='J'|h.charAt(0)=='A'||h.charAt(0)=='K')){
            if(h.charAt(0)=='A' &&r.charAt(0)!='A'){
                   System.out.println("YES");return;}
            if(r.charAt(0)=='A'&&h.charAt(0)!='A'){
                   System.out.println("NO");return;}
         int q=h.charAt(0);
         int x=r.charAt(0);
            if(h.charAt(0)=='T')
                q=q-20;
            if(r.charAt(0)=='T')
                x=x-20;
            if(h.charAt(0)=='J')
                q=q-5;
            if(r.charAt(0)=='J')
                x=x-5;
             if(h.charAt(0)=='Q')
                q=q-7;
            if(r.charAt(0)=='Q')
                x=x-7;
            if((h.charAt(1)!=r.charAt(1))&&(!(h.contains(y))&&!(r.contains(y))))
                   System.out.println("NO");
           else if(q>x)
                   System.out.println("YES");
            else if(h.charAt(0)==r.charAt(0))
                   System.out.println("NO");
            else
                   System.out.println("NO");

        }
       }
    }

}

import java.io.IOException;
import java.util.Scanner;

public class A {
	public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		char m = s.charAt(0);
		s = sc.nextLine();
		char d1 = s.charAt(0), m1 = s.charAt(1), d2 = s.charAt(3), m2 = s.charAt(4);
		if (m1 == m2) {
			if (d1 > d2) System.out.println("YES"); else System.out.println("NO");
		} else {
			if (m1 == m) System.out.println("YES"); else System.out.println("NO");
			}
		}
}

import java.util.Scanner;

public class A_Card_Game {
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		String a=input.next();
		byte s=(byte) a.charAt(0);
		String a1=input.next();
		String a2=input.next();

		byte[] s1=a1.getBytes();

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

		byte[] s2=a2.getBytes();

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

		if(s1[1]==s)
			System.out.println("YES");
		else if(s1[1]==s2[1] && s1[0]>s2[0])
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class CardGame {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String c = in.next();
		in.nextLine();
		String first = in.next();
		String second = in.next();

		HashMap<String,Integer> al = new HashMap<String,Integer>();

		al.put("6",1);
		al.put("7",2);
		al.put("8",3);
		al.put("9",4);
		al.put("T",5);
		al.put("J",6);
		al.put("Q",7);
		al.put("K",8);
		al.put("A",9);

		if (c.equals(first.charAt(1)+"")) {
			System.out.println("YES");
		} else if((first.charAt(1)+"").equals(second.charAt(1)+"")) {
			if(al.get(first.charAt(0)+"") > al.get(second.charAt(0)+"") ) {
				System.out.println("YES");
			}
		} else {
			System.out.println("NO");
		}
	}
}

import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;
import java.util.Scanner;

/**
 *
 * @author ONE BY ONE
 */
public class CardGame {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner s= new Scanner (System.in);
       String y=s.next();
       String h=s.next(); String r=s.next();
       if(h.contains(y)&&!(r.contains(y)))
            System.out.println("YES");
       else  if(!(h.contains(y))&&(r.contains(y)))
            System.out.println("NO");
       else  if(!(h.contains(y))&&!(r.contains(y))||((h.contains(y))&&(r.contains(y)))){
           int g=h.charAt(0);
           int v=r.charAt(0);
           if((g>=54&&g<=57) &&(v>=54&&v<=57))
               if(g>v)
                   System.out.println("YES");
           else
                   System.out.println("NO");

           else if((h.charAt(0)=='T'||h.charAt(0)=='Q'||h.charAt(0)=='J'|h.charAt(0)=='A'||h.charAt(0)=='K')&&(v>=54&&v<=57))
               System.out.println("YES");
  else if((r.charAt(0)=='T'||r.charAt(0)=='Q'||r.charAt(0)=='J'|r.charAt(0)=='A'||r.charAt(0)=='K')&&(g>=54&&g<=57))
               System.out.println("NO");

        else if((r.charAt(0)=='T'||r.charAt(0)=='Q'||r.charAt(0)=='J'|r.charAt(0)=='A'||r.charAt(0)=='K')&&(h.charAt(0)=='T'||h.charAt(0)=='Q'||h.charAt(0)=='J'|h.charAt(0)=='A'||h.charAt(0)=='K')){
            if(h.charAt(0)=='A'){
                   System.out.println("YES");return;}
            if(r.charAt(0)=='A'){
                   System.out.println("NO");return;}
         int q=h.charAt(0);
         int x=r.charAt(0);
            if(h.charAt(0)=='T')
                q=q-20;
            if(r.charAt(0)=='T')
                x=x-20;
            if(h.charAt(0)=='J')
                q=q-5;
            if(r.charAt(0)=='J')
                x=x-5;
             if(h.charAt(0)=='Q')
                q=q-7;
            if(r.charAt(0)=='Q')
                x=x-7;

            if(q>x)
                   System.out.println("YES");
            else
                   System.out.println("NO");

        }
       }
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACardGame solver = new ACardGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACardGame {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char suit = in.readLine().charAt(0);
            String str2[] = in.readLine().split(" ");
            HashMap<Character, Integer> map = new HashMap<>();
            map.put('6', 1);
            map.put('7', 2);
            map.put('8', 3);
            map.put('9', 4);
            map.put('T', 5);
            map.put('J', 6);
            map.put('Q', 7);
            map.put('K', 8);
            map.put('A', 9);

            String first = str2[0];
            String second = str2[1];

            if (first.charAt(1) == suit) {
                if (second.charAt(1) == first.charAt(1)) {
                    if (map.get(first.charAt(0)) > map.get(second.charAt(0)))
                        out.println("YES");
                    else
                        out.println("NO");
                } else
                    out.println("YES");
            } else {
                if (map.get(first.charAt(0)) > map.get(second.charAt(0)))
                    out.println("YES");
                else
                    out.println("NO");
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

    }
}

import java.util.Scanner;

public class test {
public static void main(String[] args) {
	String rank="6789TJQKA";
	Scanner s=new Scanner(System.in);
	String tump=s.next();
	String s1=s.next();
	String s2=s.next();

	if(s1.contains(tump+"")&&(!s2.contains(tump+""))) System.out.println("YES");
	else if(s2.contains(tump+"")&&(!s1.contains(tump+""))) System.out.println("NO");
	else{
		String a=s1.charAt(0)+"";
		String b=s2.charAt(0)+"";
		if(rank.indexOf(a)>rank.indexOf(b)) System.out.println("YES");
		else System.out.println("NO");
	}

}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

	public class A {

		public static void main(String[] args) throws Exception{
			Scanner sc = new Scanner(System.in);
			PrintWriter out = new PrintWriter(System.out);
			char trmp = sc.nextChar();
			String f = sc.next(), s = sc.next();
			if(f.charAt(1) == s.charAt(1))
				if(f.charAt(0) > s.charAt(0)) out.println("YES");
				else out.println("NO");
			else if(f.charAt(1) == trmp) out.println("YES");
			else out.println("NO");
			out.flush();
		}

		static class Scanner
		{
			StringTokenizer st;
			BufferedReader br;

			public Scanner(InputStream System){	br = new BufferedReader(new InputStreamReader(System));}
			public String next() throws IOException
			{
				while (st == null || !st.hasMoreTokens())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			}
			public String nextLine()throws IOException{return br.readLine();}
			public int nextInt() throws IOException {return Integer.parseInt(next());}
			public double nextDouble() throws IOException {return Double.parseDouble(next());}
			public char nextChar()throws IOException{return next().charAt(0);}
			public Long nextLong()throws IOException{return Long.parseLong(next());}
			public boolean ready() throws IOException{return br.ready();}
			public void waitForInput(){for(long i = 0; i < 3e9; i++);}
		}
	}

import java.util.ArrayList;
import java.util.Scanner;

public class Young {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String tramp = sc.next();
		String card1 = sc.next();
		String card2 = sc.next();
		ArrayList<Character> list = new ArrayList<Character>();
		list.add('6');
		list.add('7');
		list.add('8');
		list.add('T');
		list.add('J');
		list.add('Q');
		list.add('K');
		list.add('9');
		list.add('A');
		String res = "NO";
		if(card1.contains(tramp))
		{
			res = "YES";
		}
		if(card1.charAt(1) == card2.charAt(1))
		{
			int index1 = list.indexOf(card1.charAt(0));
			int index2 = list.indexOf(card2.charAt(0));
			if(index1 > index2)
				res = "YES";
		}
		System.out.println(res);
	}
}

 import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner;

public class CF {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                PrintWriter pw = new PrintWriter(System.out);
                String s = sc.next();
                String s1 = sc.next();
                String s2 = sc.next();
                char[] a = s.toCharArray();
                char[] b = s1.toCharArray();
                char[] c = s2.toCharArray();
                if ((a[0]== b[1]) && (a[0] != c[1])) {
                        pw.print("YES");
                } else {
                        if ((a[0]!= b[1]) && (a[0] == c[1])) {
                                pw.print("NO");
                        } else {
                                if (b[1] != c[1]) {
                                        pw.print("NO");
                                } else {
                                	if(c[0]=='T'){c[0]=11;}
                                	if(c[0]=='Q'){c[0]=12;}
                                	if(c[0]=='K'){c[0]=13;}
                                	if(c[0]=='A'){c[0]=14;}
                                        if (b[0] > c[0]) {
                                                pw.print("YES");
                                        } else {
                                                pw.print("NO");
                                        }
                                }
                        }
                }

                pw.close();
                sc.close();
        }
}

import java.io.*;
import java.util.*;

public class CF82A {

	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	// private static Timer t = new Timer();

	public CF82A() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
	}

	String next() throws IOException {
		while (st == null || !st.hasMoreElements())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	boolean hasNext() {
		if (st != null && st.hasMoreElements())
			return true;

		try {
			while (st == null || !st.hasMoreElements())
				st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			return false;
		}

		return true;
	}

	String nextLine() throws IOException {
		return br.readLine();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	void solve() throws IOException {
		HashMap<String, Integer> map = new HashMap<>();
		String[] S = { "6", "7", "8", "9","T", "J", "Q", "K", "A" };
		int[] A = { 6, 7, 8, 9, 10, 11, 12, 13, 14 };
		for (int i = 0; i < S.length; i++) {
			map.put(S[i], A[i]);
		}

		String s = next();
		char[] S1 = next().toCharArray();
		char[] S2 = next().toCharArray();

		String lastS1 = "" + S1[1], lastS2 = "" + S2[1];
		if (lastS1.equals(s)) {
			if (lastS2.equals(s)) {
				if (map.get(""+S1[0]) > map.get(""+S2[0]))
					pw.println("YES");
				else
					pw.println("NO");
			}else {
				pw.println("YES");
			}
		}else if( lastS2.equals(s)) {
			pw.println("NO");
		}else {
			if(map.get(""+S1[0]) > map.get(""+S2[0])) {
				pw.println("YES");
			}else
				pw.println("NO");
		}

		pw.flush();
	}

	public static void main(String[] args) throws IOException {
		new CF82A().solve();
	}
}

import java.util.*;
import java.io.*;

public class CardGame {

	static HashMap<Character, Integer> values;

	static {
		values = new HashMap<Character, Integer>();
		values.put('6', 6);
		values.put('7', 7);
		values.put('8', 8);
		values.put('9', 9);
		values.put('T', 10);
		values.put('J', 11);
		values.put('Q', 12);
		values.put('K', 13);
		values.put('A', 14);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		char trump = in.readLine().toCharArray()[0];
		st = new StringTokenizer(in.readLine());
		String s1 = st.nextToken();
		String s2 = st.nextToken();
		char c1 = s1.toCharArray()[0];
		char c2 = s2.toCharArray()[0];
		boolean win = false;
		if (c1 == trump && c2 != trump) {
			win = true;
		} else if (c2 == trump && c1 != trump) {
			win = false;
		} else if (c1 == c2) {
			win = values.get(c1) > values.get(c2);
		}
		if (win) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

import java.io.*;
import java.util.*;
public class card
{
    public static void main(String[] args)throws IOException
    {

    Scanner sc=new Scanner(System.in);
    String x=sc.next();
    String p=sc.next();
    String q=sc.next();
    String a[]={"6","7","8","9","T","J","Q","K","A"};
    if(p.substring(1,2).compareTo(x)==0&&p.substring(1,2).compareTo(x)!=0)
    {
        System.out.print("YES");
        return;
}
else
{
    int po=0,po1=0;
    for(int i=0;i<9;i++)
    {
        if(a[i].compareTo(p.substring(0,1))==0)
        po=i;
        if(a[i].compareTo(q.substring(0,1))==0)
        po1=i;
    }
    //System.out.println(po+" "+po1);
    if(po>po1)
    {
        System.out.print("YES");
        return;
    }
else
{
    System.out.print("NO");
    return;
}
}
}
}

import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Eslam Ashraf
 */
public class C82 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        char trump = in.nextLine().trim().charAt(0);

        String [] split = in.nextLine().trim().split(" +");

        String f = split[0];
        String s = split[1];

        if(f.charAt(1)==trump)System.out.println("YES");
        else if(f.charAt(1)==s.charAt(1) && isGreater(f.charAt(0), s.charAt(0)))System.out.println("YES");
        else System.out.println("NO");
    }

    public static boolean isGreater(char f , char s){
        char [] a = new char []{'6','7','8','9','T','J','Q','K','A'};

        for(int i =0 ; i < a.length ;i++){
            if(a[i]==f)return false;
            if(a[i]==s)return true;
        }

        return false;
    }
}

//package beta82;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A
{
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static StringTokenizer inp;
	public static void main(String[] args)  throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char trump = br.readLine().charAt(0);
		inp = new StringTokenizer(br.readLine());
		String f = inp.nextToken();
		String s = inp.nextToken();

		if(trump == f.charAt(1) && trump != s.charAt(1) || f.charAt(1) != trump && f.charAt(1) == s.charAt(1) && rank(f.charAt(0))>s.charAt(0))
			System.out.println("YES");
		else
			System.out.println("NO");

	}

	public static int rank(char c)
	{
		if(Character.isDigit(c))
		{
			return Integer.valueOf(c);
		}
		else
		{
			switch(c)
			{
			case 'T':
				return 10;
			case 'J':
				return 11;
			case 'Q':
				return 12;
			case 'K':
				return 13;
			case 'A':
				return 14;
			}
		}
		return 0;
	}

	public static int nextInt(){return Integer.parseInt(inp.nextToken());}
	public static long nextLong(){return Long.parseLong(inp.nextToken());}
	public static double nextDouble(){return Double.parseDouble(inp.nextToken());}

}

import java.util.*;
import java.io.*;

public class Prb47 {

    static FastReader sc = new FastReader();

    public static void main(String[] args) {

        Map<Character,Integer> map = new HashMap<>();

        map.put('6', 1);
        map.put('7', 2);
        map.put('8', 3);
        map.put('9', 4);
        map.put('T', 5);
        map.put('J', 6);
        map.put('Q', 7);
        map.put('K', 8);
        map.put('A', 9);

        char c = sc.next().charAt(0);
        String s = sc.nextLine();
        if(s.charAt(1) == c){
            System.out.println("YES");
        }else if(map.get(s.charAt(0)) >= map.get(s.charAt(3))){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}

import java.io.*;
import java.util.*;

/*
Good, better, best. Never let it rest. 'Til your good is better and your better is best.
 */

public class Main {

    // SOLVER
    static void solve() {
        // INPUT OUTPUT
        InputReader in = new InputReader(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int testCase = 1;
        StringBuilder result = new StringBuilder();
        while (--testCase >= 0)
        /**************************************************************************/
        {
            // SOLVE
            String trump = in.nextLine().trim();
            String[] cards = in.nextLine().trim().split("\\s+");
            if (trump.charAt(0) == cards[0].charAt(1)) {
                result.append("YES");
                break;
            }
            if (Character.getNumericValue(cards[0].charAt(0)) > Character.getNumericValue(cards[1].charAt(0))) {
                result.append("YES");
            }else {
                result.append("NO");
            }
            /*****************************************/
        }
        pw.println(result.toString().trim());
        // *************************************
        {
            pw.close();
        }
    }

    /**************************************************************************
     *************************************************************************/
    // DRIVER CODE
    public static void main(String[] args) {
        solve();
    }

    // FAST INPUT
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.*;
import java.util.*;

public class CardGame {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        String trump = f.readLine();
        StringTokenizer st = new StringTokenizer(f.readLine());
        String c1 = st.nextToken();
        String c2 = st.nextToken();
        if (c1.charAt(1) == c2.charAt(1))
            if (valueOf(c1.charAt(0)) > valueOf(c2.charAt(0)))
                System.out.println("YES");
            else
                System.out.println("NO");
        else
            if (c2.substring(1, 2).equals(trump))
                System.out.println("NO");
            else
                System.out.println("YES");

    }

    public static int valueOf(char c)
    {
        String s = "6789TJQKA";
        return s.indexOf(c);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        //Scanner in=new Scanner(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        String trump=in.readLine();
        String[] cards=in.readLine().split(" ");
        if (cards[0].contains(trump) && !cards[0].contains(trump))
            out.print("YES");
        else if (!cards[0].contains(trump) && cards[0].contains(trump))
                out.print("NO");
        else if (cards[0].compareTo(cards[1])>0) out.print("YES");
        else out.print("NO");
        out.close();
    }

}