import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz