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 ) ) {
    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" ) ;
  }
}

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 ) ) { 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 " ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (array_access array: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))) index: (decimal_integer_literal)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (array_access array: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))) index: (decimal_integer_literal)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))))))))