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();
	  //次が誰の手番か管理する変数（A,B,Cの3つの文字を扱う）
	  String turn = "A";
	  while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.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();
	  //次が誰の手番か管理する変数（A,B,Cの3つの文字を扱う）
	  String turn = "A";
	  while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.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();
	  //次が誰の手番か管理する変数（A,B,Cの3つの文字を扱う）
	  String turn = "A";
	  while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  }
	  }
  } main {
	  Scanner scan = new Scanner(System.in);
	  String S_A = scan.next();
	  String S_B = scan.next();
	  String S_C = scan.next();
	  //次が誰の手番か管理する変数（A,B,Cの3つの文字を扱う）
	  String turn = "A";
	  while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.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 turn = "A"; turn "A" while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  }
	  } true {
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  }
	  } if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  } turn.equals("A") turn.equals turn "A" {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  } if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  } S_A.length() == 0 S_A.length() S_A.length S_A 0 {
				  System.out.println("A");
				  break;
			  } System.out.println("A") System.out.println System.out System System.out "A" break; {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  } if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_A.substring(0, 1).equals("a") S_A.substring(0, 1).equals S_A.substring(0, 1) S_A.substring S_A 0 1 "a" {
					  turn = "A";
				  } turn = "A" turn "A" if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_A.substring(0, 1).equals("b") S_A.substring(0, 1).equals S_A.substring(0, 1) S_A.substring S_A 0 1 "b" {
					  turn = "B";
				  } turn = "B" turn "B" if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_A.substring(0, 1).equals("c") S_A.substring(0, 1).equals S_A.substring(0, 1) S_A.substring S_A 0 1 "c" {
					  turn = "C";
				  } turn = "C" turn "C" S_A = S_A.substring(1, S_A.length()) S_A S_A.substring(1, S_A.length()) S_A.substring S_A 1 S_A.length() S_A.length S_A if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  } turn.equals("B") turn.equals turn "B" {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  } if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  } S_B.length() == 0 S_B.length() S_B.length S_B 0 {
				  System.out.println("B");
				  break;
			  } System.out.println("B") System.out.println System.out System System.out "B" break; {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  } if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_B.substring(0, 1).equals("a") S_B.substring(0, 1).equals S_B.substring(0, 1) S_B.substring S_B 0 1 "a" {
					  turn = "A";
				  } turn = "A" turn "A" if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_B.substring(0, 1).equals("b") S_B.substring(0, 1).equals S_B.substring(0, 1) S_B.substring S_B 0 1 "b" {
					  turn = "B";
				  } turn = "B" turn "B" if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_B.substring(0, 1).equals("c") S_B.substring(0, 1).equals S_B.substring(0, 1) S_B.substring S_B 0 1 "c" {
					  turn = "C";
				  } turn = "C" turn "C" S_B = S_B.substring(1, S_B.length()) S_B S_B.substring(1, S_B.length()) S_B.substring S_B 1 S_B.length() S_B.length S_B if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  } turn.equals("C") turn.equals turn "C" {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  } if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  } S_C.length() == 0 S_C.length() S_C.length S_C 0 {
				  System.out.println("C");
				  break;
			  } System.out.println("C") System.out.println System.out System System.out "C" break; {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  } if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_C.substring(0, 1).equals("a") S_C.substring(0, 1).equals S_C.substring(0, 1) S_C.substring S_C 0 1 "a" {
					  turn = "A";
				  } turn = "A" turn "A" if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_C.substring(0, 1).equals("b") S_C.substring(0, 1).equals S_C.substring(0, 1) S_C.substring S_C 0 1 "b" {
					  turn = "B";
				  } turn = "B" turn "B" if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  } S_C.substring(0, 1).equals("c") S_C.substring(0, 1).equals S_C.substring(0, 1) S_C.substring S_C 0 1 "c" {
					  turn = "C";
				  } turn = "C" turn "C" S_C = S_C.substring(1, S_C.length()) S_C S_C.substring(1, S_C.length()) S_C.substring S_C 1 S_C.length() S_C.length S_C 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();
	  //次が誰の手番か管理する変数（A,B,Cの3つの文字を扱う）
	  String turn = "A";
	  while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.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();
	  //次が誰の手番か管理する変数（A,B,Cの3つの文字を扱う）
	  String turn = "A";
	  while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.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();
	  //次が誰の手番か管理する変数（A,B,Cの3つの文字を扱う）
	  String turn = "A";
	  while( true ){
		  if( turn.equals("A") ) {	//Aさんの番の場合
			  if( S_A.length() == 0 ) {
				  System.out.println("A");
				  break;
			  }else {
				  if( S_A.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_A.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_A.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_A = S_A.substring(1, S_A.length());
			  }
		  }else if( turn.equals("B") ) {	//Bさんの番の場合
			  if( S_B.length() == 0 ) {
				  System.out.println("B");
				  break;
			  }else {
				  if( S_B.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_B.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_B.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_B = S_B.substring(1, S_B.length());
			  }
		  }else if( turn.equals("C") ) {	//Cさんの番の場合
			  if( S_C.length() == 0 ) {
				  System.out.println("C");
				  break;
			  }else {
				  if( S_C.substring(0, 1).equals("a") ) {
					  turn = "A";
				  }else if( S_C.substring(0, 1).equals("b") ) {
					  turn = "B";
				  }else if( S_C.substring(0, 1).equals("c") ) {
					  turn = "C";
				  }
				  S_C = S_C.substring(1, S_C.length());
			  }
		  }
	  }
  }
}