import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    }
    
    static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    }
    
    static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    }
    
    static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    }
}
/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