import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        
        char isNext = 'a';//次のターンは誰か、格納
        char cnt;
        
        while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        }
        
        if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C");
        
	  }
} import java.util.*; util.* java public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        
        char isNext = 'a';//次のターンは誰か、格納
        char cnt;
        
        while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        }
        
        if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C");
        
	  }
} Main public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        
        char isNext = 'a';//次のターンは誰か、格納
        char cnt;
        
        while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        }
        
        if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C");
        
	  } main {
      	Scanner scan = new Scanner(System.in);
            
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        
        char isNext = 'a';//次のターンは誰か、格納
        char cnt;
        
        while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        }
        
        if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C");
        
	  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String Sa = scan.next(); Sa scan.next() scan.next scan String Sb = scan.next(); Sb scan.next() scan.next scan String Sc = scan.next(); Sc scan.next() scan.next scan char isNext = 'a'; isNext 'a' char cnt; cnt while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        } Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 Sa.length() != 0 Sa.length() Sa.length Sa 0 Sb.length() != 0 Sb.length() Sb.length Sb 0 Sc.length() != 0 Sc.length() Sc.length Sc 0 {
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        } if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break; isNext == 'a' && Sa.length() >= 1 isNext == 'a' isNext 'a' Sa.length() >= 1 Sa.length() Sa.length Sa 1 {
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          } isNext = Sa.substring(0, 1).charAt(0) isNext Sa.substring(0, 1).charAt(0) Sa.substring(0, 1).charAt Sa.substring(0, 1) Sa.substring Sa 0 1 0 Sa = Sa.substring(1, Sa.length() ) Sa Sa.substring(1, Sa.length() ) Sa.substring Sa 1 Sa.length() Sa.length Sa if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break; isNext == 'a' && Sa.length() == 0 isNext == 'a' isNext 'a' Sa.length() == 0 Sa.length() Sa.length Sa 0 break; if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break; isNext == 'b' && Sb.length() >= 1 isNext == 'b' isNext 'b' Sb.length() >= 1 Sb.length() Sb.length Sb 1 {
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          } isNext = Sb.substring(0, 1).charAt(0) isNext Sb.substring(0, 1).charAt(0) Sb.substring(0, 1).charAt Sb.substring(0, 1) Sb.substring Sb 0 1 0 Sb = Sb.substring(1, Sb.length() ) Sb Sb.substring(1, Sb.length() ) Sb.substring Sb 1 Sb.length() Sb.length Sb if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break; isNext == 'b' && Sb.length() == 0 isNext == 'b' isNext 'b' Sb.length() == 0 Sb.length() Sb.length Sb 0 break; if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break; isNext == 'c' && Sc.length() >= 1 isNext == 'c' isNext 'c' Sc.length() >= 1 Sc.length() Sc.length Sc 1 {
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          } isNext = Sc.substring(0, 1).charAt(0) isNext Sc.substring(0, 1).charAt(0) Sc.substring(0, 1).charAt Sc.substring(0, 1) Sc.substring Sc 0 1 0 Sc = Sc.substring(1, Sc.length() ) Sc Sc.substring(1, Sc.length() ) Sc.substring Sc 1 Sc.length() Sc.length Sc if( isNext == 'c' && Sc.length() == 0 )break; isNext == 'c' && Sc.length() == 0 isNext == 'c' isNext 'c' Sc.length() == 0 Sc.length() Sc.length Sc 0 break; if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C"); isNext == 'a' && Sa.length() == 0 isNext == 'a' isNext 'a' Sa.length() == 0 Sa.length() Sa.length Sa 0 System.out.println("A") System.out.println System.out System System.out "A" if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C"); isNext == 'b' && Sb.length() == 0 isNext == 'b' isNext 'b' Sb.length() == 0 Sb.length() Sb.length Sb 0 System.out.println("B") System.out.println System.out System System.out "B" if( isNext == 'c' && Sc.length() == 0)System.out.println("C"); isNext == 'c' && Sc.length() == 0 isNext == 'c' isNext 'c' Sc.length() == 0 Sc.length() Sc.length Sc 0 System.out.println("C") System.out.println System.out System System.out "C" String args[] args public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        
        char isNext = 'a';//次のターンは誰か、格納
        char cnt;
        
        while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        }
        
        if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C");
        
	  }
} public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        
        char isNext = 'a';//次のターンは誰か、格納
        char cnt;
        
        while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        }
        
        if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C");
        
	  }
} Main
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String Sa = scan.next();
        String Sb = scan.next();
        String Sc = scan.next();
        
        char isNext = 'a';//次のターンは誰か、格納
        char cnt;
        
        while( Sa.length() != 0 || Sb.length() != 0 || Sc.length() != 0 ){
          if( isNext == 'a' && Sa.length() >= 1){
            isNext = Sa.substring(0, 1).charAt(0);
            Sa = Sa.substring(1, Sa.length() );
          }
          else if( isNext == 'a' && Sa.length() == 0 )break;
          
          else if( isNext == 'b' && Sb.length() >= 1){
            isNext = Sb.substring(0, 1).charAt(0);
            Sb = Sb.substring(1, Sb.length() );
          }
          else if( isNext == 'b' && Sb.length() == 0 )break;
          
          else if( isNext == 'c' && Sc.length() >= 1){
            isNext = Sc.substring(0, 1).charAt(0);
            Sc = Sc.substring(1, Sc.length() );
          }
          else if( isNext == 'c' && Sc.length() == 0 )break;
        }
        
        if( isNext == 'a' && Sa.length() == 0)System.out.println("A");
        else if( isNext == 'b' && Sb.length() == 0)System.out.println("B");
        else if( isNext == 'c' && Sc.length() == 0)System.out.println("C");
        
	  }
}