public static void main ( String [ ] args ) {
  MyScanner sc = new MyScanner ( ) ;
  String s_a = sc . next ( ) ;
  String s_b = sc . next ( ) ;
  String s_c = sc . next ( ) ;
  int la = s_a . length ( ) ;
  int lb = s_b . length ( ) ;
  int lc = s_c . length ( ) ;
  int a = la ;
  int b = lb ;
  int c = lc ;
  char turn = 'a' ;
  String ans = null ;
  boolean end = false ;
  while ( ! end ) {
    switch ( turn ) {
      case ( 'a' ) : if ( a == 0 ) {
        end = true ;
        ans = "A" ;
        break ;
      }
      turn = s_a . charAt ( la - a ) ;
      a -- ;
      break ;
      case ( 'b' ) : if ( b == 0 ) {
        end = true ;
        ans = "B" ;
        break ;
      }
      turn = s_b . charAt ( lb - b ) ;
      b -- ;
      break ;
      case ( 'c' ) : if ( c == 0 ) {
        end = true ;
        ans = "C" ;
        break ;
      }
      turn = s_c . charAt ( lc - c ) ;
      c -- ;
      break ;
    }
  }
  System . out . println ( ans ) ;
}

public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; String s_a = sc . next ( ) ; String s_b = sc . next ( ) ; String s_c = sc . next ( ) ; int la = s_a . length ( ) ; int lb = s_b . length ( ) ; int lc = s_c . length ( ) ; int a = la ; int b = lb ; int c = lc ; char turn = ' a ' ; String ans = null ; boolean end = false ; while ( ! end ) { switch ( turn ) { case ( ' a ' ) : if ( a == 0 ) { end = true ; ans = " A " ; break ; } turn = s_a . charAt ( la - a ) ; a -- ; break ; case ( ' b ' ) : if ( b == 0 ) { end = true ; ans = " B " ; break ; } turn = s_b . charAt ( lb - b ) ; b -- ; break ; case ( ' c ' ) : if ( c == 0 ) { end = true ; ans = " C " ; break ; } turn = s_c . charAt ( lc - c ) ; c -- ; break ; } } System . out . println ( ans ) ; }
(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)))) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (character_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (null_literal))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (false))) (while_statement condition: (parenthesized_expression (unary_expression operand: (identifier))) body: (block (switch_expression condition: (parenthesized_expression (identifier)) body: (switch_block (switch_block_statement_group (switch_label (parenthesized_expression (character_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (string_literal))) (break_statement))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (parenthesized_expression (character_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (string_literal))) (break_statement))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (parenthesized_expression (character_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (string_literal))) (break_statement))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))))) (expression_statement (update_expression (identifier))) (break_statement)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))