import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        StringBuilder sb=new StringBuilder();

        String a=scan.next();
        String b=scan.next();
        String c=scan.next();

        int []anum=new int [a.length()];
        int []bnum=new int[b.length()];
        int []cnum=new int[c.length()];


        anum=strToint(a);
        bnum=strToint(b);
        cnum=strToint(c);
        int []cnt=new int[3];
        String ans;
        int tmp=0;
        while(true){
            if(tmp==0){
                if(cnt[0]>=a.length()){
                    ans="A";
                    break;
                }
                tmp=anum[cnt[0]];
                cnt[0]++;
            }
            else if(tmp==1){
                if(cnt[1]>=b.length()){
                    ans="B";
                    break;
                }
                tmp=bnum[cnt[1]];
                cnt[1]++;
            }
            else if(tmp==2){
                if(cnt[2]>=c.length()){
                    ans="C";
                    break;
                }
                tmp=cnum[cnt[2]];
                cnt[2]++;
            }


        }
        System.out.println(ans);
        //System.out.println(cnt[0]+" "+cnt[1]+" "+cnt[2]);


    }
     static int[] strToint(String  a){

        int []ans=new int[a.length()];
        for(int i=0;i<a.length();i++){
            ans[i]=a.charAt(i)-'a';
        }
        return ans;
    }
}

/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