import java.util.Scanner;
public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  String[] S_Array = { S_A, S_B, S_C };
	  String[] S_NameArray = { "A", "B", "C" };
	  String turn = "A";
	  for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  String[] S_Array = { S_A, S_B, S_C };
	  String[] S_NameArray = { "A", "B", "C" };
	  String turn = "A";
	  for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  }
  }
} Main public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  String[] S_Array = { S_A, S_B, S_C };
	  String[] S_NameArray = { "A", "B", "C" };
	  String turn = "A";
	  for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  }
  } main {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  String[] S_Array = { S_A, S_B, S_C };
	  String[] S_NameArray = { "A", "B", "C" };
	  String turn = "A";
	  for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  }
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String S_A = scan.next(); S_A scan.next() scan.next scan String S_B = scan.next(); S_B scan.next() scan.next scan String S_C = scan.next(); S_C scan.next() scan.next scan String[] S_Array = { S_A, S_B, S_C }; S_Array { S_A, S_B, S_C } S_A S_B S_C String[] S_NameArray = { "A", "B", "C" }; S_NameArray { "A", "B", "C" } "A" "B" "C" String turn = "A"; turn "A" for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  } int i = 0 ; int i = 0 ; i 0 i++ i++ i {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  } {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  } if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  } turn.equals( S_NameArray[i % 3] ) turn.equals turn S_NameArray[i % 3] S_NameArray i % 3 i 3 {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  } if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  } S_Array[i % 3].length() == 0 S_Array[i % 3].length() S_Array[i % 3].length S_Array[i % 3] S_Array i % 3 i 3 0 {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  } System.out.println( S_NameArray[i % 3] ) System.out.println System.out System System.out S_NameArray[i % 3] S_NameArray i % 3 i 3 break; {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  } String S_lead = S_Array[i % 3].substring(0, 1); S_lead S_Array[i % 3].substring(0, 1) S_Array[i % 3].substring S_Array[i % 3] S_Array i % 3 i 3 0 1 if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  } S_lead.equals("a") S_lead.equals S_lead "a" {
					  turn = "A";
				  } turn = "A" turn "A" if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  } S_lead.equals("b") S_lead.equals S_lead "b" {
					  turn = "B";
				  } turn = "B" turn "B" if( S_lead.equals("c") ) {
					  turn = "C";
				  } S_lead.equals("c") S_lead.equals S_lead "c" {
					  turn = "C";
				  } turn = "C" turn "C" S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length()) S_Array[i % 3] S_Array i % 3 i 3 S_Array[i % 3].substring(1, S_Array[i % 3].length()) S_Array[i % 3].substring S_Array[i % 3] S_Array i % 3 i 3 1 S_Array[i % 3].length() S_Array[i % 3].length S_Array[i % 3] S_Array i % 3 i 3 String[] args args public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  String[] S_Array = { S_A, S_B, S_C };
	  String[] S_NameArray = { "A", "B", "C" };
	  String turn = "A";
	  for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  }
  }
} public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  String[] S_Array = { S_A, S_B, S_C };
	  String[] S_NameArray = { "A", "B", "C" };
	  String turn = "A";
	  for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  }
  }
} Main
import java.util.Scanner;
public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  String[] S_Array = { S_A, S_B, S_C };
	  String[] S_NameArray = { "A", "B", "C" };
	  String turn = "A";
	  for( int i = 0 ;; i++ ) {
		  if( turn.equals( S_NameArray[i % 3] ) ) {
			  if( S_Array[i % 3].length() == 0 ) {
				  System.out.println( S_NameArray[i % 3] );
				  break;
			  }else {
				  String S_lead = S_Array[i % 3].substring(0, 1);
				  if( S_lead.equals("a") ) {
					  turn = "A";
				  }else if( S_lead.equals("b") ) {
					  turn = "B";
				  }else if( S_lead.equals("c") ) {
					  turn = "C";
				  }
				  S_Array[i % 3] = S_Array[i % 3].substring(1, S_Array[i % 3].length());
			  }
		  }
	  }
  }
}