n=input()
p,k=list(map(str,input().split()))
jim=["6","7","8","9","T","J","Q","K","A"]
if n not in p and n not in k:
    if p[1]==k[1]:
        if jim.index(p[0])>jim.index(k[0]):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
else:
    if n in p and n not in k:
        print("YES")
    elif n not in p and n in k:
        print("NO")
    else:
        if jim.index(p[0])>jim.index(k[0]):
            print("YES")
        else:
            print("NO")

mast=['6','7','8','9','T','J','Q','K','A']
m=raw_input()
a=list(x for x in raw_input())
if (a[4]==m):
    if (a[1]==m) & (mast.index(a[0])>mast.index(a[3])):
        print ('YES')
    else:
        print ('NO')
else:
    if (a[1]==m):
        print ('YES')
    else:
        if(a[1]==a[4]) & (mast.index(a[0])>mast.index(a[3])):
            print ('YES')
        else:
            print ('NO')

trump = raw_input()
x = raw_input()
first = x[:2:]
second = x[3::]
d = {
        "6": 1,
        "7": 2,
        "8": 3,
        "9": 4,
        "T": 5,
        "J": 6,
        "Q": 7,
        "K": 8,
        "A": 9
        }
if(first[1] == second[1]):
    if(d[first[0]] > d[second[0]]):
        print "YES"
    else:
        print "NO"
elif(first[1] == trump):
    print "YES"
else:
    print "NO"

import sys
import itertools
import math

def compare(a, b):
    ranks = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
    if ranks.index(a) > ranks.index(b):
        return True
    else:
        return False

if __name__ == '__main__':
    tramp = raw_input()
    cards = raw_input()
    a = cards.split(" ")[0]
    b = cards.split(" ")[1]

    if a[-1] == b[-1]:
        if compare(a[0], b[0]):
            print "YES"
        else:
            print "NO"
    elif a[-1] == tramp:
        print "YES"
    else:
        print "NO"

t = raw_input()
l,r = list(raw_input().split())
rank = '6789TJQKA'
if l[1] == t and r[1] != t:
    print "YES"
elif (l[1] != t and r[1] == t) or (l[1] != r[1]):
    print "NO"
elif rank.index(l[0]) > rank.index(r[0]):
    print "YES"
else:
    print "NO"

def check(f, s, trump):
    if f[0] == s[0]:
        if f[1] > s[1]:
            return 1
        else:
            return 0
    if f[0] == trump:
        return 1
    return 0
trump = raw_input()
f, s = raw_input().split(" ")
number = "6789TJQKA"
suit = "SHDC"
f = [suit.find(f[1]), number.find(f[0])]
s = [suit.find(s[1]), number.find(s[0])]
trump = suit.find(trump)
print ["NO","YES"][check(f, s, trump)]

def rank(c):
    s="6789TJQKA"
    return s.find(c)
t=input()
s=input()
s1, s2=s.split(sep=" ")
if s1[1]==t and s2[1]!=t:
    print('YES')
elif s1[1]==s2[1] and rank(s1[0])>=rank(s2[0]):
    print('YES')
else:
    print('NO')

rnk = "6789TJQKA"
t = raw_input()
a,b = raw_input().split()
if a[1] == b[1]:
    print "YES" if rnk.index(a[0]) > rnk.index(b[0]) else "NO"
elif a[1] == t:
    print "YES"
else:
    print "NO"

rank="6789TJQKA"
trump=input()
card=input()
r1=card[0]
s1=card[1]
r2=card[3]
s2=card[4]
if(s1==trump):
    if(s2!=trump):
        print("YES")
    elif(rank.index(r1)>rank.index(r2)):
        print("YES")
    else:
        print("NO")
elif(s1==s2 and rank.index(r1)>rank.index(r2)):
        print("YES")
else:
    print("NO")

RANK = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]

def compareRank(a, b):
    return RANK.index(a[0]) > RANK.index(b[0])

t = input()
a, b = input().split(' ')
s = 'NO'
if a[1] == t:
    if b[1] != t or (b[1] == t and compareRank(a, b)):
        s = 'YES'
elif compareRank(a, b) and b[1] != t and a[1] == b[1]:
    s = 'YES'
print(s)

tramp = raw_input()
c1,c2 = raw_input().split()

rank1 = c1[0]
suit1 = c1[1]

rank2 = c2[0]
suit2 = c2[1]

yes = False

if suit1 == tramp:
	if suit2 != tramp:
		yes = True
RANK = ['6','7','8','9','T','J','Q','K','A']
def order(x):
	for i in range(len(RANK)):
		if RANK[i] == x:
			return i

if suit1 == suit2 and order(rank1) > order(rank2):
	yes = True

if yes:
	print 'YES'
else:
	print 'NO'

suits = ["S","H","D","C"]
cards = {"6":1,"7":2,"8":3,"9":4,"T":5,"J":6,"Q":7,"K":8,"A":9}
trump = raw_input()
f,s = raw_input().split()
if(f[1]==trump and s[1]!=f[1]):
    print "YES"
elif(f[1]!=trump and s[1]==trump):
    print "NO"
elif(f[1]==s[1]==trump):
    print "YES" if cards[f[0]]>cards[s[0]] else "NO"
else:
    print "NO" if f[1]!=s[1] else "YES" if (cards[f[0]]>cards[s[0]]) else "NO"

#start the code from here

trump=input()
fir,sec=map(str,input().split())
trlist=["S", "H", "D","C"]
rank=["6", "7", "8", "9", "T", "J", "Q", "K","A"]
if fir[1]==trump and sec[1]!=trump:
	print("YES")
elif fir[1]==sec[1]:
	if rank.index(fir[0])>rank.index(sec[0]):
		print("YES")
	else:
		print("NO")
else:
	print("NO")

trump=str(input())
a,b=map(str,input().split())
d={"6":6, "7":7, "8":8, "9":9, "T":10, "J":11, "Q":12, "K":13,"A":14}
if list(a)[1]==trump and list(b)[1]!=trump:
    print("YES")
elif list(b)[1]==trump and list(a)[1]!=trump:
    print("NO")
else:
    if list(a)[1]!=list(b)[1]:
        print("NO")
    else:
        if d[list(a)[0]]>d[list(b)[0]]:
            print("YES")
        else:
            print("NO")

ts = input()

g=["6", "7", "8", "9"]
h=["T", "J", "Q", "K" , "A"]
a,b = input().split()

if a[-1] == b[-1]:

    if a[0] in g:
        if b[0] in h:
            print('NO')
        elif b[0] in g:
            if g.index(a[0])>g.index(b[0]):
                print('YES')
            else:
                print('NO')
    elif a[0] in h:
        if b[0] in g:
            print('YES')
        elif b[0] in h:
            if h.index(a[0])>h.index(b[0]):
                print('YES')
            else:
                print('NO')
else:

    if a[-1] == ts:
        print('YES')
    else:
        print('NO')

T=raw_input()
S=raw_input().split()
A=S[0]
B=S[1]
L={'6':0,'7':1,'8':2,'9':3,'T':4,'J':5,'Q':6,'K':7,'A':8}
flag1=False
flag2=False
if(A[1]==T):
	flag1=True
if(B[1]==T):
	flag2=True
if(flag1 and flag2):
	if(L[A[0]]>L[B[0]]):
		print "YES"
	else:
		print "NO"
elif(flag1):
	print "YES"
elif(flag2):
	print "NO"
else:
	if(A[1]==B[1] and L[A[0]]>L[B[0]]):
		print "YES"
	else:
		print "NO"

t = str(input())
s1, s2 = map(str,input().split())
temp = "6789TJQKA"
if s1[1] == s2[1]:
	print("YES" if temp.find(s1[0]) > temp.find(s2[0]) else "NO")
else:
	print("YES" if s1[1] == t else "NO")

s=input()
c=input()
a='6789TJQKA'
if(c[1]==s and c[1]!=c[len(c)-1]):
    print("YES")
else:
    if(c[1]==c[len(c)-1] and a.find(c[0])>a.find(c[len(c)-2])):
        print("YES")
    else:
        print("NO")

from sys import stdin

buf = []
for line in stdin:
    buf.append(line.strip())
buf.reverse()

c = '6789TJQKA'
trump = buf.pop()
first, second = tuple(buf.pop().split())
if first[1] == trump and second[1] != trump:
    print 'YES'
else:
    if first[1] == second[1] and c.find(first[0]) > c.find(second[0]):
        print 'YES'
    else:
        print 'NO'

cards_nominals = ['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
SUIT_INDEX = 1
NOMINAL_INDEX = 0

def compareCardsNominals(card1, card2):
    if card1 == card2: return 0

    if cards_nominals.index(card1) > cards_nominals.index(card2):
        return 1
    return -1

def isBeaten(trump, striker_card, card):
    beaten = False

    if striker_card[SUIT_INDEX] == card[SUIT_INDEX]:
        if compareCardsNominals(striker_card[NOMINAL_INDEX], card[NOMINAL_INDEX]) > 0:
            beaten = True
    elif striker_card[SUIT_INDEX] == trump:
        beaten = True

    return beaten

if __name__ == '__main__':
    trump = raw_input()
    cards = raw_input()
    cards_list = cards.partition(' ')
    striker_card = cards_list[0]
    card = cards_list[2]

    print 'YES' if isBeaten(trump, striker_card, card) else 'NO'

trump = input()
c1, c2 = input().split()

ranks = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]

if c1[1] == trump:
    if c1[1] == c2[1]:
        if ranks.index(c1[0]) > ranks.index(c2[0]):
            print("YES")
        else:
            print("NO")
    else:
        print("YES")
elif c1[1] == c2[1] and ranks.index(c1[0]) > ranks.index(c2[0]):
    print("YES")
else:
    print("NO")

trump = str(input())
carda, cardb = [str(x) for x in input().strip().split()]
win = 0
deck = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
ranka = deck.index(carda[0])
rankb = deck.index(cardb[0])
if(carda[1]==cardb[1]):
	#same suit
	if(ranka > rankb):
		win=1
	elif(ranka < rankb):
		win=2
else:
	if(carda[1]==trump[0]):
		win=1
	elif(cardb[1]==trump[0]):
		win=2

if(win==1):
	print("YES")
else:
	print("NO")

def val(x):
    if x == '6':
        return 6
    elif x == '7':
        return 7
    elif x == '8':
        return 8
    elif x == '9':
        return 9
    elif x == 'T':
        return 10
    elif x == 'J':
        return 11
    elif x == 'Q':
        return 12
    elif x == 'K':
        return 13
    else:
        return 14

C = raw_input().strip()
c = C[0]

L = raw_input().strip().split()
tmp1 = L[0]
tmp2 = L[1]

if tmp1[1] == tmp2[1] and val(tmp1[0]) > val(tmp2[0]):
    print 'YES'
elif tmp1[1] != tmp2[1] and tmp1[1] == c:
    print 'YES'
else:
    print 'NO'

######################################################################
# Write your code here
import sys
from math import *
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip()) # for strings to list of char
from collections import defaultdict as df
import heapq
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
infinite = float('inf')
#######################################################################
l=list("6789TJQKA")

t=input().strip()
s,p=input().split()
if(s[1]==t and p[1]!=t):
    print("YES")
elif(s[1]==p[1]):
    if(l.index(s[0])>l.index(p[0])):
        print("YES")
    else:
        print("NO")
else:
    print("NO")

best = input()
order = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
first, second = tuple([string for string in input().split()])
if(first[1] == second[1]):
	if(order.index(first[0]) > order.index(second[0])):
		print("YES")
	else:
		print("NO")
else:
	if(first[1] == best):
		print("YES")
	else:
		print("NO")

# if(second[1] == best and first[1] != best):
# 	print("NO")
# elif(order.index(first[0]) > order.index(second[0])):
# 	print("YES")
# elif(first[1] == best):
# 	print("YES")
# else:
# 	print("NO")

s=input()
a,b=input().split()
x="6789TJQKA"
if a[1]==s and b[1]!=s: print("YES")
elif b[1]==s and a[1]!=s: print("NO")
elif a[1]!=b[1]: print("NO")
elif x.index(a[0])>x.index(b[0]): print("YES")
else: print("NO")

class CodeforcesTask106ASolution:
    def __init__(self):
        self.result = ''
        self.trump = ''
        self.cards = []

    def read_input(self):
        self.trump = input()
        self.cards = input().split(" ")

    def process_task(self):
        order = "6789TJQKA"
        if self.trump == self.cards[0][1]:
            if self.trump == self.cards[1][1]:
                if order.index(self.cards[0][0]) > order.index(self.cards[1][0]):
                    self.result = "YES"
                else:
                    self.result = "NO"
            else:
                self.result = "YES"
        else:
            if self.cards[0][1] == self.cards[1][1]:
                if order.index(self.cards[0][0]) > order.index(self.cards[1][0]):
                    self.result = "YES"
                else:
                    self.result = "NO"
            else:
                self.result = "NO"

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask106ASolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())

import sys
import math
import itertools
import collections

def getdict(n):
    d = {}
    if type(n) is list or type(n) is str:
        for i in n:
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    else:
        for i in range(n):
            t = ii()
            if t in d:
                d[t] += 1
            else:
                d[t] = 1
    return d
def cdiv(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a*b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return int(str(n)[::-1])
def prime(n):
    if n == 2:
        return True
    if n % 2 == 0 or n <= 1:
        return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0:
            return False
    return True

#arr =['v', '^', '>', '<']
d = ['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
mast = ['S', 'H', 'D', 'C']
kozir = input()
cards = list(input().split())
if cards[0][1] == kozir and cards[1][1] != kozir or cards[0][1] == kozir and cards[1][1] == kozir and \
    d.index(cards[0][0]) > d.index(cards[1][0]) or cards[0][1] == cards[1][1] and d.index(cards[0][0]) > d.index(cards[1][0]):
    print('YES')
else:
    print('NO')

a=input()
h=['6','7','8','9','T','J','Q','K','A']
s=[n for n in input().split()]
p=s[0]
q=s[1]
if p[1]==q[1] :
  if h.index(p[0])>h.index(q[0]):
    print('YES')
  else:
    print('NO')
else:
  if p[1]==a and q[1]!=a:
    print('YES')
  else:
    print('NO')

a=input()
b,c=input().split()
def rank(x):
	z=['6','7','8','9','T','J','Q','K','A']
	p=0
	for y in z:
		p+=1
		if y==x:
			return p

if(a[0]==b[1]and a[0]!=c[1]):
	print("YES")
elif(b[1]==c[1]):
	if(rank(b[0])>rank(c[0])):
		print("YES")
	else:
		print("NO")
else:
	print("NO")

trump= input()
first, scd = input().split()
d = {"6" : 6, "7":7 ,"8" :8, "9":9, "T":10, "J":11, "Q":12, "K":13,  "A":14}

if trump in first and trump not in scd:
  print('YES')
elif trump in scd and trump not in first:
  print('NO')
elif first[1] == scd[1]:

  print(['NO','YES'][d[first[0]]>d[scd[0]]])
else :
  print('NO')

import sys

rang=['6','7','8','9','T','J','Q','K','A']

t=raw_input().strip()
een,twee=raw_input().split()

if een[1]==t and twee[1]!=t:
    print 'YES'
elif een[1]!=t and twee[1]==t:
    print 'NO'
elif rang.index(een[0])>rang.index(twee[0]) and een[1]==twee[1]:
    print 'YES'
else:
    print 'NO'

suit = raw_input()
first, second = raw_input().split(' ')
d = {
        '6' : 6,
        '7' : 7,
        '8' : 8,
        '9' : 9,
        'T' : 10,
        'J' : 11,
        'Q' : 12,
        'K' : 13,
        'A' : 14,
        }
if first[1] == suit and second[1] != suit:
    print 'YES'
elif first[1] != second[1]:
    print 'NO'
else:
    print 'YES' if d[first[0]] > d[second[0]] else 'NO'

# -*- coding: utf-8 -*-
import sys
if __name__ == '__main__':

    dict = {'6':6,'7':7,'8':8,'9':9,'T':10,'J':11,'Q':12,'K':13,'A':14}
    num = map(str,sys.stdin.readline().split())
    str1,str2 =map(str,sys.stdin.readline().split())

    if str1[1] == num[0]:
        if str2[1] != num[0]:
            print "YES"
        else:
            if dict[str1[0]] > dict[str2[0]]:
                print "YES"
            else:
                print "NO"
    else:
        if str1[1] != str2[1]:
            print "NO"
        else:
            if dict[str1[0]] > dict[str2[0]]:
                print "YES"
            else:
                print "NO"

trump=input()
s1,s2=input().split()
l1=['6','7','8','9','T','J','Q','K','A']
if s1[1]==trump:
    if s2[1]==trump:
        if l1.index(s1[0])>l1.index(s2[0]):
            print("YES")
        else :
            print("NO")
    else :
        print("YES")
else :
    if s1[1]!=s2[1]:
        print("NO")
    else :
        if l1.index(s1[0])>l1.index(s2[0]):
            print("YES")
        else :
            print("NO")

s=input()
l=input().split()
z='6789TJQKA'
flag=0
if l[0][1]!=s and l[0][1]!=l[1][1]:
	print('NO')
	exit()
if l[0][1]==s:
	if l[1][1]==s:
		if z.index(l[0][0])>z.index(l[1][0]):
			flag=1
	else:
		flag=1
else:
	if l[1][1]!=s:
		if z.index(l[0][0])>z.index(l[1][0]):
			flag=1
if flag==1:
	print('YES')
else:
	print('NO')

t=input()
a,b=input().split()
c='6789TJQKA'
if a[1]==b[1]:
    if c.find(a[0])>c.find(b[0]):
        print('YES')
    else:
        print('NO')
elif a[1]==t and b[1]!=t:
    print('YES')
else:
    print('NO')

tc = input()
card1, card2 = input().split()
card1suit = card1[1]
card2suit = card2[1]
card1val = card1[0]
card2val = card2[0]

if card1suit == tc and card2suit != tc:
    print('YES')
    exit()
def rank_val(s):
    if s == '6' or s == '7' or s == '8' or s == '9':
        return int(s)
    elif s == 'T':
        return 10
    elif s == 'J':
        return 11
    elif s == 'Q':
        return 12
    elif s == 'K':
        return 13
    elif s == 'A':
        return 14

if card1suit == card2suit:
    if rank_val(card1val) > rank_val(card2val):
        print('YES')
        exit()
    else:
        print('NO')
        exit()
print('NO')

rank=["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
trump=raw_input("")
l=raw_input("").split(" ")
first=l[0]
second=l[1]
if first[1]==trump or (first[1]==second[1] and rank.index(first[0])>rank.index(second[0])):
    if second[1]==trump and rank.index(first[0])<rank.index(second[0]):
        print "NO"
    else:
        print "YES"
else:
    print "NO"

import sys
suits = ['S','H','D','C']
card_order = ['6', '7', '8', '9', 'T', 'J', 'Q', 'K','A']

trump = raw_input()
cards = raw_input().split()
first = cards[0]
second = cards[1]

first_card_idx = card_order.index(first[0])
second_card_idx = card_order.index(second[0])
first_suit = first[1]
second_suit = second[1]

if (first_suit == trump) and (second_suit != trump):
       print "YES"
elif (first_suit == second_suit) and (first_card_idx > second_card_idx):
       print "YES"
else:
       print "NO"

ranks = dict()
ranks['6'] = 0
ranks['7'] = 1
ranks['8'] = 2
ranks['9'] = 3
ranks['T'] = 4
ranks['J'] = 5
ranks['Q'] = 6
ranks['K'] = 7
ranks['A'] = 8

tramp = raw_input()
cards = raw_input().split()
first = cards[0]
second = cards[1]

if first[1] == second[1]:
    if ranks[first[0]] > ranks[second[0]]:
        print 'YES'
    else:
        print 'NO'
elif first[1] == tramp:
    print 'YES'
else:
    print 'NO'

suit = ['S', 'H', 'D', 'C']
rank = ['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']

trump = str(raw_input())
cards = str(raw_input())

win = False

if cards[1] == cards[4] and rank.index(cards[0]) > rank.index(cards[3]):
    win = True

if cards[1] == trump and cards[4] != trump:
    win = True

if win:
    print('YES')
else:
    print('NO')

s = '6789TJQKA'
t = raw_input()
a, b = raw_input().split()
print ['NO', 'YES'][(a[1] == t and b[1] != t) or (a[1] == b[1] and s.find(a[0]) > s.find(b[0]))]

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
input = sys.stdin
output = sys.stdout

M = ['S','H','D','C']
V = ['6','7','8','9','T','J','Q','K','A']

def solve(km,c1,c2):
    v = lambda c: V.index(c[0])
    m = lambda c: M.index(c[1])
    m1 = m(c1)
    m2 = m(c2)
    v1 = v(c1)
    v2 = v(c2)
    if m1 == m2:
        if v1 > v2:
            return 'YES'
    else:
        if m1 == M.index(km):
            return 'YES'
    return 'NO'

km = input.readline().strip()
C = input.readline().strip().split(' ')
c1 = C[0]
c2 = C[1]

a = solve(km,c1,c2)
output.write('%s\n' % a)

RANKS = "6789TJQKA"
def is_first_winner(tramp, first, second):
	if first[1] == second[1]:
		if RANKS.find(first[0]) > RANKS.find(second[0]):
			return "YES"
		else:
			return "NO"
	if first[1] == tramp:
		return "YES"
	return "NO"

tramp = raw_input()
first, second = raw_input().split()
print is_first_winner(tramp, first, second)

import atexit, io, sys
buffer = io.BytesIO()
sys.stdout = buffer

@atexit.register
def write():
	sys.__stdout__.write(buffer.getvalue())

def rank(c):
	return ["6", "7", "8", "9", "T", "J", "Q", "K","A"].index(c)

trump=raw_input()
cards=[ [c for c in card ] for card in raw_input().split(' ') ]

#print cards
ans=0
if cards[0][1]==cards[1][1]:
	if rank( cards[0][0] )> rank(cards[1][0]):
		ans+=1
else:
	if cards[0][1]==trump:
		ans+=1

if ans:
	print "YES"
else:
	print "NO"

trump = raw_input()
a, b =raw_input().split(" ")
d = ["6", "7", "8", "9", "T", "J", "Q", "K","A"]

if a[1]==b[1]:
    if d.index(a[0])>d.index(b[0]):
        print "YES"
    else:
        print "NO"
elif a[1] == trump:
    print "YES"
else:
    print "NO"

trump = raw_input()
a,b= raw_input().split()
cards = '6789TJQKA'
if trump==a[1]==b[1]:
    if cards.index(a[0])>cards.index(b[0]):
        print 'YES'
    else:
        print 'NO'
elif trump==a[1]:
    print 'YES'
elif trump==b[1]:
    print 'NO'
else:
    if a[1]==b[1] and cards.index(a[0])>cards.index(b[0]):
        print 'YES'
    else:
        print 'NO'

mast = raw_input()
card1, card2 = (raw_input().split())
if (card1[1] != card2[1]) and (card1[1] == mast):
    print 'YES'
elif (card1[1] != card2[1]) and (card1[1] != mast):
    print 'NO'
else:
    a = []
    a.append('6')
    a.append('7')
    a.append('8')
    a.append('9')
    a.append('T')
    a.append('J')
    a.append('Q')
    a.append('K')
    a.append('A')
    ind1 = a.index(card1[0],0,len(a))
    ind2 = a.index(card2[0],0,len(a))
    if ind1 > ind2:
        print 'YES'
    else:
        print 'NO'

from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
setrecursionlimit(10**7)
dX= [ 0, 0, 1,-1, 1,-1, 1,-1]
dY= [ 1,-1, 0, 0, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
#################################################
s1=RS()[0]
s2,s3=RS()
s="6789TJQKA"
rank={s[i]:i for i in range(len(s))}
if (s2[1]==s3[1] and rank[s2[0]]>rank[s3[0]]) or (s2[1]==s1 and s3[1]!=s1):
    print("YES")
else:
    print("NO")

tc = input()
str1 = input().split()
first = str1[0]
second = str1[1]
order = ['6','7','8','9','T','J','Q','K','A']
if(first[1] == tc and second[1] != tc):
    print('YES')
elif first[1] != tc and second[1] == tc:
    print('NO')
elif first[1] == second[1]:
    if order.index(first[0]) > order.index(second[0]):
        print ('YES')
    else:
        print ('NO')
else:
    print ('NO')

##############--->>>>> Deepcoder Amit Kumar Bhuyan <<<<<---##############

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii():  return int(input())
def si():  return input()
def mi():  return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li():  return list(mi())

def dmain():
    sys.setrecursionlimit(1000000)
    threading.stack_size(1024000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import log,sqrt,factorial,cos,tan,sin,radians
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *
#import threading
#from itertools import permutations
#Copy 2D list  m = [x[:] for x in mark] .. Avoid Using Deepcopy
import sys
input = sys.stdin.readline
scan_int = lambda: int(input())
scan_string = lambda: input().rstrip()
read_list = lambda: list(read())
read = lambda: map(int, input().split())
read_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) :

    result = n
    p = 2
    while(p * p<= n) :
        if (n % p == 0) :
            while (n % p == 0) :
                n = n // p
            result = result * (1.0 - (1.0 / (float) (p)))
        p = p + 1
    if (n > 1) :
        result = result * (1.0 - (1.0 / (float)(n)))

    return (int)(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False

	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		# print(low, mid, high)
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

## for checking any conditions
def check(beauty, s, n, count):
	pass

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
alphs = "abcdefghijklmnopqrstuvwxyz".upper()

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	tramp = scan_string()
	card1, card2 = input().split()
	d = {"6": 1, "7": 2, "8": 3, "9": 4, "T": 5, "J": 6, "Q": 7, "K": 8, "A": 9}
	if card1[1] == tramp:
		if card2[1] != tramp:
			print("YES")
			return
		else:
			if d[card1[0]] > d[card2[0]]:
				print("YES")
				return
			else:
				print("NO")
				return
	elif card1[1] == card2[1]:
		if d[card1[0]] > d[card2[0]]:
			print("YES")
			return
		else:
			print("NO")
			return
	else:
		print("NO")

# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    for i in range(1):
    	solve()
    #dmain()

# Comment Read()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))

big = {
    'T': 10,
    'J': 11,
    'Q': 12,
    'K': 13,
    'A': 14
}

tr = input()

first, second = input().split()

if first[0] in big:
    fv = big[first[0]]
else:
    fv = int(first[0])

if second[0] in big:
    sv = big[second[0]]
else:
    sv = int(second[0])

if (first[1] == tr and second[1] != tr) or (fv > sv and first[1] == second[1]):
    print("YES")
else:
    print("NO")

import sys
def read_values():
  return map(int,raw_input().split())

r = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]

t = raw_input()
c = raw_input().split()
res = 'NO'
if c[0][1]==c[1][1]:
  if r.index(c[0][0])>r.index(c[1][0]):
    res='YES'
else:
  if t==c[0][1]:
    res='YES'
print res

z = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]

trmp = raw_input()
a, b = raw_input().split()

if a[1] != b[1]:
	if a[1] == trmp:
		print 'YES'
	else:
		print 'NO'
else:
	x, y = -1, -1
	for i in range(len(z)):
		if z[i] == a[0]:
			x = i
		if z[i] == b[0]:
			y = i
	if x > y:
		print "YES"
	else:
		print "NO"

prioritylist ={

    '6': 1,
    "7":2,
    '8':3,
    '9':4,
    'T':5,
    'J':6,
    'Q':7,
    'K':8,
    'A':9,
}

trump = input()

fir,sec = map(str,input().split())

if trump == fir[1]:
    print('YES')

elif sec[1]!=fir[1]:
    print('NO')

elif sec[1]==fir[1] and prioritylist[fir[0]] > prioritylist[sec[0]]:
    print('YES')

else:
    print('NO')

rank = {"6":1, "7":2, "8":3, "9":4, "T":5, "J":6, "Q":7, "K":8,"A":9}
trump = raw_input()
first,second = map(str,raw_input().split())
if trump == first[1] and trump != second[1]:
    print "YES"
elif first[1] == second[1]:
    if rank[first[0]] > rank[second[0]]:
        print "YES"
else:
    print "NO"

def great():
	a.split()
	b.split()
	if s.index(a[0]) > s.index(b[0]):

		print("YES")
	else:
		print("NO")

t=input()
a,b=map(str,input().split())
s='6789TJQKA'
if(t in a):
	if t in b:
		great()
	else:
		print("YES")
elif(t in b):
	print("NO")
else:
	print("NO")

####################################################
# -*- coding: utf-8 -*-
import sys

w = sys.stdout.write
read = sys.stdin.readline
reads = sys.stdin.read

def r(f=None):
    if f:
        return map(f, read().split())
    else:
        return read().split()

def rs(t,f=None):
    result = []
    result_append = result.append
    for i in xrange(t):
        if f:
            result_append(tuple(map(f, read().split())))
        else:
            result_append(read().replace('\n', ''))
    return result

####################################################
import math
sqrt = math.sqrt
#from collections import deque

s = read().replace('\n', '')
a, b = read().split()
a = list(a)
b = list(b)
rep = {"T": 10, "J": 11, "Q": 12, "K": 13, "A": 14}
if a[0] in "TJQKA":
    a[0] = rep[a[0]]
if b[0] in "TJQKA":
    b[0] = rep[b[0]]
a[0] = int(a[0])
b[0] = int(b[0])

if (a[0] > b[0] and a[1] == b[1]) or (b[1] != s and b[1] != a[1]):
    w("YES")
else:
    w("NO")

order="6789TJQKA"
suit=raw_input()
card=raw_input()
[a,b]=card.split()
if (a[1]==suit)&(b[1]!=suit):
    print "YES"
elif (a[1]!=suit) &(b[1]==suit):
    print "NO"
elif order.index(a[0])>order.index(b[0]):
    print "YES"
#print suit,card

suit = ['S', 'H', 'D', 'C']
rank = ['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']

trump = str(raw_input())
cards = str(raw_input())

win = False

if cards[1] == cards[4] and rank.index(cards[0]) > rank.index(cards[3]):
    win = True

if cards[1] == trump and cards[3] != trump:
    win = True

if win:
    print('YES')
else:
    print('NO')

tr = input()
t1,t2 = map(str,input().split())
g = ['A','K','Q','J','T']
if tr in t1 and tr not in t2:
    print('YES')
elif tr not in t1 and tr in t2:
    print('NO')
else:
    s1 = t1[0]
    s2 = t2[0]
    if s1 in g and s2 in g:
        l1 = g.index(s1)
        l2 = g.index(s2)
        if s1>s2:
            print('NO')
        else:
            print('YES')
    elif s1 in g:
        print('YES')
    elif s2 in g:
        print('NO')
    else:
        s1,s2 = int(s1),int(s2)
        if s1>s2:
            print('YES')
        else:
            print('NO')

t = raw_input()
l,r = list(raw_input().split())
rank = '6789TJQKA'
if l[1] == t and r[1] != t:
    print "YES"
elif l[1] != t and r[1] == t:
    print "NO"
elif rank.index(l[0]) > rank.index(r[0]):
    print "YES"
else:
    print "NO"

trump= input()

ranks=['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
cards= input().split()
a= cards[0]
b= cards[1]

if a[1]==trump and b[1]==trump:
    if ranks.index(a[0])> ranks.index(b[0]):
        print('YES')
        exit()
    else:
        print('NO')
        exit()
    exit()

if b[1]==trump:
    print('NO')
    exit()

if ranks.index(a[0])> ranks.index(b[0]) or a[1]==trump and b[1]!=trump:
    print('YES')
else:
    print('NO')

trump = raw_input("")
c = raw_input("").split()

for i in range (0,2) :
	c[i].replace("T","A");
	c[i].replace("J","B");
	c[i].replace("Q","C");
	c[i].replace("K","D");
	c[i].replace("A","E");

if  c[0][1] == c[1][1]:
	if c[0][0] > c[1][0]:
		print "YES"
	else:
		print "NO"
elif c[0][1] == trump[0]:
	print "YES"
elif c[1][1] == trump[0]:
	print "NO"
else:
	print "NO"

suit = ['S', 'H', 'D', 'C']
rank = ['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']

trump = str(raw_input())
cards = str(raw_input())

win = False

if cards[1] == cards[4] and rank.index(cards[0]) > rank.index(cards[3]):
    win = True

if cards[1] == trump:
    win = True

if win:
    print('YES')
else:
    print('NO')

ranks = dict()
ranks['6'] = 0
ranks['7'] = 1
ranks['8'] = 2
ranks['9'] = 3
ranks['T'] = 4
ranks['J'] = 5
ranks['Q'] = 6
ranks['K'] = 7
ranks['A'] = 8

tramp = raw_input()
cards = raw_input().split()
first = cards[0]
second = cards[1]

if first[1] == tramp:
    print 'YES'
elif second[1] == tramp:
    print 'NO'
elif first[1] == second[1]:
    if ranks[first[0]] > ranks[second[0]]:
        print 'YES'
    else:
        print 'NO'
else:
    print 'NO'

tramp = raw_input()
a, b = raw_input().split()
s = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
if a[1] ==tramp and b[1] != tramp:
    print 'YES'
else:
    print 'YES' if s.index(a[0]) > s.index(b[0]) else 'NO'

l=["6","7","8","9","T","J","Q","K","A"]
s=input()
a,b = input().split()
if a[1] is b[1] and a[1] is s:
    if l.index(a[0]) > l.index(b[0]):
        print("YES")
    else: print("NO")

elif a[1] is b[1] and a[1] is not s:
    if l.index(a[0]) > l.index(b[0]):
        print("YES")
    else: print("NO")

elif a[1] is not b[1] and a[1] is not s:
    if b[1] is s:
        print("NO")
    else:
        if l.index(a[0]) > l.index(b[0]):
            print("YES")
        else: print("NO")

elif a[1] is not b[1] and a[1] is s:
    print("YES")

else: print("NO")

a=input()
f,s=input().split()
f.replace("A","14")
f.replace("K","13")
f.replace("Q","12")
f.replace("J","11")
f.replace("T","10")
s.replace("A","14")
s.replace("K","13")
s.replace("Q","12")
s.replace("J","11")
s.replace("T","10")

if a==f[1]:
    print("YES")
else:
    if f[1]!=s[1]:
        print("NO")
    else:
        if int(f[0])>int(s[0]):
            print("YES")
        else:
            print("NO")

seq = ["6", "7", "8", "9", "T", "J", "Q", "K" , "A"]
rank =["S", "H", "D" , "C"]
trump = str(input())
first , second = map(str , input().split())
fr = first[0]
fs = first[1]
sr = second[0]
ss = second[1]
if fs==trump:
    if ss==trump:
        if seq.index(fr)>seq.index(sr):
            print("YES")
        else:
            print("NO")
    else:
        print("YES")
elif ss==trump:
    print("NO")
else:
    if fs==ss:
        if seq.index(fr)>seq.index(sr):
            print("YES")
        else:
            print("NO")
    elif rank.index(fs)<rank.index(ss):
        print("YES")
    else:
        print("NO")

Trump=raw_input()
Cards= raw_input()
l = list(Cards)
l.append(Trump)
l = [w.replace('T', '10') for w in l]
l = [w.replace('J', '11') for w in l]
l = [w.replace('Q', '12') for w in l]
l = [w.replace('K', '13') for w in l]
l = [w.replace('A', '14') for w in l]
l = [w.replace('S', '4') for w in l]
l = [w.replace('H', '3') for w in l]
l = [w.replace('D', '2') for w in l]
l = [w.replace('C', '1') for w in l]

if (l[1]==l[5] and l[4]!=l[5]):
    print 'YES'
elif (l[1]!=l[5] and l[4]==l[5]):
    print 'NO'
elif (int(l[1])>int(l[4])):
    print 'YES'
elif (int(l[1])<int(l[4])):
    print 'NO'
elif (l[1]==l[4] and int(l[0])>int(l[3])):
    print 'YES'
elif (l[1]==l[4] and int(l[0])<int(l[3])):
    print 'NO'

z = [6, 7, 8, 9, "T", "J", "Q", "K", "A"]

trmp = raw_input()
a, b = raw_input().split()

if a[1] != b[1]:
	if a[1] == trmp:
		print 'YES'
	else:
		print 'NO'
else:
	x, y = -1, -1
	for i in range(len(z)):
		if z[i] == a[0]:
			x = i
		if z[i] == b[0]:
			y = i
	if x > y:
		print "YES"
	else:
		print "NO"

atu=[]
carti=[]
carte1=[]
carte2=[]
atu=raw_input()
carti=raw_input()
ok=0
for i in carti:
	if i==' ':
		ok=1
		continue
	if ok==0:
		carte1.append(i)
	else:
		carte2.append(i)

msg=0
index={'6':0, '7':1, '8':2, '9':3, 'T':4, 'J':5, 'Q':6, 'K':7, 'A':8}
if carte1[1]==atu[0]:
	if carte2[1]==atu[0]:
		if index[carte1[0]]<index[carte2[0]]:
			msg=0
		else:
			msg=1
	else:
		msg=1
else:
	if carte2[0]==atu[0]:
		msg=0
	else:
		if index[carte1[0]]<index[carte2[0]]:
			msg=0
		else:
			msg=1

if msg==0:
	msg='NO'
else:
	msg='YES'

RANKS = "6789TJQKA"
def card_strength(tramp, card):
	strength = RANKS.find(card[0])
	if tramp == card[1]:
		strength += 100
	return strength

tramp = raw_input()
first, second = raw_input().split()
if card_strength(tramp, first) > card_strength(tramp,second):
	print "YES"
else:
	print "NO"

n=raw_input()
p =raw_input()
ans="YES"
rank=["6", "7", "8", "9", "T", "J", "Q", "K","A"]

if p[4]==n:
	ans = "NO"
else:
	if (rank.index(p[0])<rank.index(p[3])):
		ans = "NO"
print ans

trump= input()

ranks=['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
cards= input().split()
a= cards[0]
b= cards[1]

if ranks.index(a[0])> ranks.index(b[0]) or a[1]==trump and b[1]!=trump:
    print('YES')
else:
    print('NO')

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
#start = time.clock()
n=raw_input()
f,s=map(str, raw_input().split())
#絵柄保存
f1,s1=f[1],s[1]
if f[0]=='T': f2=10
elif f[0]=='J': f2=11
elif f[0]=='Q': f2=12
elif f[0]=='K': f2=13
elif f[0]=='A': f2=14
else: f2=int(f[0])

if s[1]==('6' or '7' or '8' or '9'):
    s2=int(s[0])
if s[0]=='T': s2=10
elif s[0]=='J': s2=11
elif s[0]=='Q': s2=12
elif s[0]=='K': s2=13
elif s[0]=='A': s2=14
else: s2=int(s[0])

if n==f1:
    print 'YES'
elif f1==s1 and f2>s2:
    print 'YES'
else:
    print 'NO'

import sys

def solve():
    trump = sys.stdin.readline().strip()
    f, s = sys.stdin.readline().split()
    res = 0
    ranks = "6789TJQKA"
    if f[1] == trump and s[1] == trump:
        if ranks.find(f[0]) > ranks.find(s[0]):
            res = 1
        else:
            res = 0
    elif f[1] == trump and s[1] != trump:
        res = 1
    elif f[1] != trump and s[1] == trump:
        res = 0
    else:
        res = 0
    print "YES" if res else "NO"

solve()

trump= input()

ranks=['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
cards= input().split()
a= cards[0]
b= cards[1]

if ranks.index(a[0])> ranks.index(b[0]) or a[0]==trump:
    print('YES')
else:
    print('NO')

def great():
	a.split()
	b.split()
	if s.index(a[0]) > s.index(b[0]):

		print("YES")
	else:
		print("NO")

t=input()
a,b=map(str,input().split())
s='6789TJQKA'
if(t in a):
	if t in b:
		great()
	else:
		print("YES")
elif(t in b):
	print("NO")
else:
	print("NO")

#!/usr/bin/python
#(c) Andreev Alexander (aka Carzil) 2011
m = str(raw_input())
k1, k2 = raw_input().split()
carts = {"6": 1,
         "7": 2,
         "8": 3,
         "9": 4,
         "T": 5,
         "J": 6,
         "Q": 7,
         "K": 8,
         "A": 9}
if k1[1] == m:
    if k2[1] == m:
        print "NO"
    else:
        print "YES"
elif k1[1] == k2[1]:
    if carts[k1[0]] > carts[k2[0]]:
        print "YES"
    else:
        print "NO"
else:
    print "NO"

trump = raw_input("")
c = raw_input("").split()

for i in range (0,2) :
	c[i]=c[i].replace("T","B");
	c[i]=c[i].replace("J","C");
	c[i]=c[i].replace("Q","D");
	c[i]=c[i].replace("K","E");
	c[i]=c[i].replace("A","F");

print c[0],c[1]

if  c[0][1] == c[1][1]:
	if c[0][0] > c[1][0]:
		print "YES"
	else:
		print "NO"
elif c[0][1] == trump[0]:
	print "YES"
elif c[1][1] == trump[0]:
	print "NO"
else:
	print "NO"

s=input()
a,b=map(str,input().split())
rank = ['6','7','8','9','T','J','Q','K','A']

if (a[1]==s and b[1]==s) or (a[1]!=s and b[1]!=s):
    if rank.index(a[0])<rank.index(b[0]):
        print('NO')
        #print('1')
    elif rank.index(a[0])>rank.index(b[0]):
        print('YES')
        #print('2')
    else:
        print("NO")
        #print('3')

else:
    if a[1]==s:
        print('YES')
        #print('4')
    elif b[1]==s:
        print('NO')
        #print('5')

a=input()
cc=input()
cc=cc.split(" ")
b=cc[0]
c=cc[1]
l=["6", "7", "8", "9", "T", "J", "Q", "K","A"]

if(a in b and a not in c):
    print("YES")
elif(a not in b and a in c):
    print("NO")
else:
    if(l.index(b[0])>l.index(c[0])):
        print("YES")
    else:
        print("NO")

tramp = raw_input()
a, b = raw_input().split()
s = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
if a[1] ==tramp and b[1] != tramp:
    print 'YES'
else:
    print 'YES' if s.index(a[0]) > s.index(b[0]) else 'NO'

def getValue(s):
  if s == 'T':
    return 10
  elif s == 'J':
    return 11
  elif s == 'Q':
    return 12
  elif s == 'K':
    return 13
  elif s == 'A':
    return 14
  else:
    return int(s)

trump = raw_input()

line = raw_input().split()
first = line[0]
second = line[1]

if first[1] == second[1] and first[1] != trump and second[1] != trump:
  if getValue(first[0]) > getValue(second[0]):
    print "YES"
elif first[1] == trump and second[1] != trump:
  print "YES"
else:
  print "NO"

a=input()
k=(input().split())
l='6789JQKA'
if a in k[0]:print("YES")
elif k[0][1]!=k[1][1]:print("NO")
elif k[0][1]==k[1][1] and l.index(k[0][0])>l.index(k[1][0]):print("YES")
else:print("NO")

trump = raw_input()
a,b= raw_input().split()
cards = '6789TJQKA'
if trump==a[1]:
    print 'YES'
elif trump==b[1]:
    print 'NO'
else:
    if a[1]==b[1] and cards.index(a[0])>cards.index(b[0]):
        print 'YES'
    else:
        print 'NO'

a=input()
h=['6','7','8','9','T','J','Q','K','A']
s=[n for n in input().split()]
p=s[0]
q=s[1]
if p[1]==q[1] and p[1]!=a:
  if h.index(p[0])>h.index(q[0]):
    print('YES')
  else:
    print('NO')
else:
  if p[1]==a and q[1]!=a:
    print('YES')
  else:
    print('NO')

def compare(s1,s2):
    x = "6 7 8 9 T J Q K A".split()
    for i in range (9):
        if s1 == x[i]:
            t1 = i
        if s2 == x[i]:
            t2 = i
    return t1 > t2

n = input()
res = 'NO'
s = input().split()
if s[0][1] == s[1][1]:
    if compare(s[0][0],s[1][0]):
        res = 'YES'
else:
    if s[0][1] == n:
        res = 'YES'

print('YES')

s1=input()
s2=input()
if s2[1]==s1 and s2[-1]!=s1:print('YES')
elif s2[1]==s2[-1] and s2[0]>s2[-2]:print('YES')
else:print('NO')

t = raw_input()
f, s = raw_input().split()
r = '6789TJQKA'
print ['NO', 'YES'][f[1] == t and not s[1] == t or f[1] == t and s[1] == t and r.find(f[0]) > r.find(s[0])]

l=['6','7','8','9','T','J','Q','K','A']
trump = input()
card1,card2=input().split()
if card1[1] == trump:
    if card2[1] == trump:
        print('YES' if l.index(card1[0])>l.index(card2[0]) else 'NO')
    else:
        print('YES')
else:
    if card2[1] == trump:
        print('NO')
    else:
        print('YES' if l.index(card1[0])>l.index(card2[0]) else 'NO')

a=['6','7','8','9','T',"J","Q","K","A"]
trump=input()
first,second=input().split()
if first[1]==trump and first[1]!=second[1]:
    print("YES")
elif first[1]==second[1]:
    if a.index(first[0])>a.index(second[0]):
        print('YES')
else:
    print("NO")

tramp = raw_input()
a, b = raw_input().split()
s = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
if a[1] ==tramp and b[1] != tramp:
    print 'YES'
elif a[1] != tramp and b[1] == tramp:
    print 'NO'
else:
    print 'YES' if s.index(a[0]) > s.index(b[0]) else 'NO'

ranks = ['6','7','8','9','T','J','Q','K','A']

tr = input()
a,b = map(str,input().split())

if(tr in a):
    print('YES')
else:
    if(ranks.index(a[0]) >= ranks.index(b[0])):
        print('YES')
    else:
        print('NO')

trump=['S','H','D','C']
rank=[ '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' ]
s=input()
t=input()
if s in trump and s not in t:
    print("YES")
else:
    if t[1]!=t[-1]:
        print("NO")
    else:
        if rank.index(t[0])-rank.index(t[3])>0:
            print("YES")
        else:
            print("NO")

suit = ['S', 'H', 'D', 'C']
rank = ['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']

trump = str(raw_input())
cards = str(raw_input())

win = False

if cards[1] == cards[4] and rank.index(cards[0]) > rank.index(cards[3]):
    win = True

if cards[1] == trump:
    win = True

if win:
    print('YES')
else:
    print('NO')

def great():
	a.split()
	b.split()
	if s.index(a[0]) > s.index(b[0]):

		print("YES")
	else:
		print("NO")

t=input()
a,b=map(str,input().split())
s='6789TJQKA'
if(t in a):
	if t in b:
		great()
	else:
		print("YES")
elif(t in b):
	print("NO")
else:
	great()

tr = input()
t1,t2 = map(str,input().split())
g = ['A','K','Q','J','T']
if tr in t1 and tr not in t2:
    print('YES')
elif tr not in t1 and tr in t2:
    print('NO')
else:
    s1 = t1[0]
    s2 = t2[0]
    if s1 in g and s2 in g:
        l1 = g.index(s1)
        l2 = g.index(s2)
        if l1>l2:
            print('NO')
        elif l1==l2:
            print('NO')
        else:
            print('YES')
    elif s1 in g:
        print('YES')
    elif s2 in g:
        print('NO')
    elif s1 not in g and s2 not in g:
        s1,s2 = int(s1),int(s2)
        if t1[1]==t2[1]:
            if s1>s2:
                print('YES')
            elif s1==s2:
                print('NO')
            else:
                print('NO')
        else:
            print('NO')

s=input()
c=input()
a='6789TJQKA'
if(c[1]==s and c[1]!=c[len(c)-1]):
    print("******YES")
else:
    if(c[1]==c[len(c)-1] and a.find(c[0])>a.find(c[len(c)-2])):
        print("YES")
    else:
        print("NO")

trump= input()

ranks=['6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
cards= input().split()
a= cards[0]
b= cards[1]

if ranks.index(a[0])> ranks.index(b[0]) or a[1]==trump and b[1]!=trump:
    print('YES')
else:
    print('NO')

trump = input()
[cart1, cart2] = list(input().split())
rank1, suit1 = cart1[0], cart1[1]
rank2, suit2 = cart2[0], cart2[1]
ranks = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
suits = ["S", "H", "D", "C"]
if(suits.index(suit1) == suits.index(suit2) and ranks.index(rank1) > ranks.index(rank2)) or trump == suit1:
    print("YES")
else:
    print("NO")

trump = raw_input()[0]
s1, s2 = raw_input().split(' ')

vs = '6789TJQKA'

if (s1[1] == trump and s2[1] != trump) or ((s2[1] != trump or (s1[1] == trump and s2[1] == trump)) and vs.index(s1[0]) > vs.index(s2[0])):
    print 'YES'
else:
    print 'NO'

t=input()
a,b=input().split()
if a[1]==b[1]:
    if a[0]>b[0]:
        print('YES')
    else:
        print('NO')
elif a[1]==t and b[1]!=t:
    print('YES')
else:
    print('NO')

rnk = "6789TJQKA"
t = raw_input()
a,b = raw_input().split()
if a[1] == t:
    print "YES"
elif a[1] == b[1]:
    print "YES" if rnk.index(a[0]) > rnk.index(b[0]) else "NO"
else:
    print "NO"

suits={'S','H','D','C'}
ranks={'6':0,'7':1,'8':2,'9':3,'T':4,'J':5,'Q':6,'K':7,'A':8}
trump=input()
card1,card2=input().split()
if card1[1]==trump:
    if card2[1]==trump:
        if(ranks[card1[0]]>ranks[card2[0]]):
            print("YES")
        else:
            print("NO")
    else:
        print("YES")
else:
    if card2[1]==trump:
        print("NO")
    else:
        if(ranks[card1[0]]>ranks[card2[0]]):
            print("YES")
        else:
            print("NO")

trump = raw_input()
x = raw_input()
first = x[:2:]
second = x[3::]
d = {
        "6": 1,
        "7": 2,
        "8": 3,
        "9": 4,
        "T": 5,
        "J": 6,
        "Q": 7,
        "K": 8,
        "A": 9
        }
if(first[1] == trump):
    print "YES"
elif(second[1] == trump):
    print "NO"
elif(d[first[0]] > d[second[0]]):
    print "YES"
else:
    print "NO"

tr = input()
t1,t2 = map(str,input().split())
g = ['A','K','Q','J','T']
if tr in t1 and tr not in t2:
    print('YES')
elif tr not in t1 and tr in t2:
    print('NO')
else:
    s1 = t1[0]
    s2 = t2[0]
    if s1 in g and s2 in g:
        l1 = g.index(s1)
        l2 = g.index(s2)
        if s1>s2:
            print('NO')
        elif s1==s2:
            print('NO')
        else:
            print('YES')
    elif s1 in g:
        print('YES')
    elif s2 in g:
        print('NO')
    else:
        s1,s2 = int(s1),int(s2)
        if s1>s2:
            print('YES')
        elif s1==s2:
            print('NO')
        else:
            print('NO')

s=input()
a,b=input().split()
x="6789TJQKA"
if a[1]==s: print("YES")
elif b[1]==s or a[1]!=b[1]: print("NO")
elif x.index(a[0])>x.index(b[0]): print("YES")
else: print("NO")

big = {
    'T': 10,
    'J': 11,
    'Q': 12,
    'K': 13,
    'A': 14
}

tr = input()

first, second = input().split()

if first[0] in big:
    fv = big[first[0]]
else:
    fv = int(first[0])

if second[0] in big:
    sv = big[second[0]]
else:
    sv = int(second[0])

if (first[1] == tr and second[1] != tr) or fv > sv:
    print("YES")
else:
    print("NO")

atu=[]
carti=[]
carte1=[]
carte2=[]
atu=raw_input()
carti=raw_input()
ok=0
for i in carti:
	if i==' ':
		ok=1
		continue
	if ok==0:
		carte1.append(i)
	else:
		carte2.append(i)

msg=0
index={'6':0, '7':1, '8':2, '9':3, 'T':4, 'J':5, 'Q':6, 'K':7, 'A':8}
if carte1[1]==atu[0]:
	if carte2[1]==atu[0]:
		if index[carte1[0]]<index[carte2[0]]:
			msg=0
		else:
			msg=1
	else:
		msg=1
else:
	if carte2[0]==atu[0]:
		msg=0
	else:
		if index[carte1[0]]<=index[carte2[0]]:
			msg=0
		else:
			msg=1

if msg==0:
	msg='NO'
else:
	msg='YES'

def getValue(s):
  if s == 'T':
    return 10
  elif s == 'J':
    return 11
  elif s == 'Q':
    return 12
  elif s == 'K':
    return 13
  elif s == 'A':
    return 14
  else:
    return int(s)

trump = raw_input()

line = raw_input().split()
first = line[0]
second = line[1]

if first[1] == trump and second[1] != trump:
  print "YES"
elif first[1] == second[1]:
  if getValue(first[0]) > getValue(second[0]):
    print "YES"
else:
  print "NO"

trump = raw_input()
x = raw_input()
first = x[:2:]
second = x[3::]
d = {
        "6": 1,
        "7": 2,
        "8": 3,
        "9": 4,
        "T": 5,
        "J": 6,
        "Q": 7,
        "K": 8,
        "A": 9
        }
if(first[1] != second[1]):
    if(first[1] == trump):
        print "YES"
    elif(second[1] == trump):
        print "NO"
elif(d[first[0]] > d[second[0]]):
    print "YES"
else:
    print "NO"

def getValue(s):
  if s == 'T':
    return 10
  elif s == 'J':
    return 11
  elif s == 'Q':
    return 12
  elif s == 'K':
    return 13
  elif s == 'A':
    return 14
  else:
    return int(s)

trump = raw_input()

line = raw_input().split()
first = line[0]
second = line[1]

if first[1] == trump and second[1] != trump:
  print "YES"
elif first[1] == second[1]:
  if getValue(first[0]) > getValue(second[0]):
    print "YES"
elif first[1] == trump and second[1] == trump:
  if getValue(first[0]) > getValue(second[0]):
    print "YES"
else:
  print "NO"

big = {
    'T': 10,
    'J': 11,
    'Q': 12,
    'K': 13,
    'A': 14
}

tr = input()

first, second = input().split()

if first[0] in big:
    fv = big[first[0]]
else:
    fv = int(first[0])

if second[0] in big:
    sv = big[second[0]]
else:
    sv = int(second[0])

if first[1] == tr and second[1] != tr or fv > sv:
    print("YES")
else:
    print("NO")

s1=input()
s2=input()
if s2[1]==s1 and s2[-1]!=s1:print('YES')
elif s2[1]==s2[-1] and s2[0]>s2[-2]:print('YES')
else:print('NO')

t = input()
f , s = input().split()
rank = ["6", "7", "8", "9", "T", "J", "Q", "K" , "A"]
ans='NO'
if f[1]==t:
    ans='YES'
elif f[1]==s[1]:
    if rank.index(f[0]) > rank.index(s[0]):
        ans='YES'
print(ans)

n=raw_input()
p =raw_input()
ans="NO"
rank=["6", "7", "8", "9", "T", "J", "Q", "K","A"]

if p[1] ==n and p[4] == n:
	if (rank.index(p[0])>rank.index(p[3])):
		ans = 'YES'
elif p[1]==n:
	ans = "YES"
elif p[4] ==n:
	ans="NO"
else:
	if (rank.index(p[0])>rank.index(p[3])):
		ans = "YES"
print ans