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;
    }
} import java.util.Scanner; Scanner java.util 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;
    }
} 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]);


    } main {
        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]);


    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) StringBuilder sb=new StringBuilder(); sb new StringBuilder() String a=scan.next(); a scan.next() scan.next scan String b=scan.next(); b scan.next() scan.next scan String c=scan.next(); c scan.next() scan.next scan int []anum=new int [a.length()]; anum new int [a.length()] a.length() a.length a int []bnum=new int[b.length()]; bnum new int[b.length()] b.length() b.length b int []cnum=new int[c.length()]; cnum new int[c.length()] c.length() c.length c anum=strToint(a) anum strToint(a) strToint a bnum=strToint(b) bnum strToint(b) strToint b cnum=strToint(c) cnum strToint(c) strToint c int []cnt=new int[3]; cnt new int[3] 3 String ans; ans int tmp=0; 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]++;
            }


        } 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]++;
            }


        } 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]++;
            } tmp==0 tmp 0 {
                if(cnt[0]>=a.length()){
                    ans="A";
                    break;
                }
                tmp=anum[cnt[0]];
                cnt[0]++;
            } if(cnt[0]>=a.length()){
                    ans="A";
                    break;
                } cnt[0]>=a.length() cnt[0] cnt 0 a.length() a.length a {
                    ans="A";
                    break;
                } ans="A" ans "A" break; tmp=anum[cnt[0]] tmp anum[cnt[0]] anum cnt[0] cnt 0 cnt[0]++ cnt[0] cnt 0 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]++;
            } tmp==1 tmp 1 {
                if(cnt[1]>=b.length()){
                    ans="B";
                    break;
                }
                tmp=bnum[cnt[1]];
                cnt[1]++;
            } if(cnt[1]>=b.length()){
                    ans="B";
                    break;
                } cnt[1]>=b.length() cnt[1] cnt 1 b.length() b.length b {
                    ans="B";
                    break;
                } ans="B" ans "B" break; tmp=bnum[cnt[1]] tmp bnum[cnt[1]] bnum cnt[1] cnt 1 cnt[1]++ cnt[1] cnt 1 if(tmp==2){
                if(cnt[2]>=c.length()){
                    ans="C";
                    break;
                }
                tmp=cnum[cnt[2]];
                cnt[2]++;
            } tmp==2 tmp 2 {
                if(cnt[2]>=c.length()){
                    ans="C";
                    break;
                }
                tmp=cnum[cnt[2]];
                cnt[2]++;
            } if(cnt[2]>=c.length()){
                    ans="C";
                    break;
                } cnt[2]>=c.length() cnt[2] cnt 2 c.length() c.length c {
                    ans="C";
                    break;
                } ans="C" ans "C" break; tmp=cnum[cnt[2]] tmp cnum[cnt[2]] cnum cnt[2] cnt 2 cnt[2]++ cnt[2] cnt 2 System.out.println(ans) System.out.println System.out System System.out ans String[] args args 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;
    } strToint {

        int []ans=new int[a.length()];
        for(int i=0;i<a.length();i++){
            ans[i]=a.charAt(i)-'a';
        }
        return ans;
    } int []ans=new int[a.length()]; ans new int[a.length()] a.length() a.length a for(int i=0;i<a.length();i++){
            ans[i]=a.charAt(i)-'a';
        } int i=0; int i=0; i 0 i<a.length() i a.length() a.length a i++ i++ i {
            ans[i]=a.charAt(i)-'a';
        } {
            ans[i]=a.charAt(i)-'a';
        } ans[i]=a.charAt(i)-'a' ans[i] ans i a.charAt(i)-'a' a.charAt(i) a.charAt a i 'a' return ans; ans String  a a 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;
    }
} 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;
    }
} Main
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;
    }
}
