import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        boolean test = true;
        String ans = "";
        char ch = 'a';
        
        while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        boolean test = true;
        String ans = "";
        char ch = 'a';
        
        while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        boolean test = true;
        String ans = "";
        char ch = 'a';
        
        while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        boolean test = true;
        String ans = "";
        char ch = 'a';
        
        while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S1 = sc.next(); S1 sc.next() sc.next sc String S2 = sc.next(); S2 sc.next() sc.next sc String S3 = sc.next(); S3 sc.next() sc.next sc boolean test = true; test true String ans = ""; ans "" char ch = 'a'; ch 'a' while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        } test {
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        } if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            } ch == 'a' ch 'a' {
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            } if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                } S1.length()>1 S1.length() S1.length S1 1 {
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                } ch = S1.charAt(0) ch S1.charAt(0) S1.charAt S1 0 S1 = S1.substring(1,S1.length()) S1 S1.substring(1,S1.length()) S1.substring S1 1 S1.length() S1.length S1 if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                } S1.length()==1 S1.length() S1.length S1 1 {
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                } ch = S1.charAt(0) ch S1.charAt(0) S1.charAt S1 0 S1 = "" S1 "" {
                    ans = "A";
                    test = false;
                } ans = "A" ans "A" test = false test false if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            } ch == 'b' ch 'b' {
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            } if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                } S2.length()>1 S2.length() S2.length S2 1 {
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                } ch = S2.charAt(0) ch S2.charAt(0) S2.charAt S2 0 S2 = S2.substring(1,S2.length()) S2 S2.substring(1,S2.length()) S2.substring S2 1 S2.length() S2.length S2 if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                } S2.length()==1 S2.length() S2.length S2 1 {
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                } ch = S2.charAt(0) ch S2.charAt(0) S2.charAt S2 0 S2 = "" S2 "" {
                    ans = "B";
                    test = false;
                } ans = "B" ans "B" test = false test false {
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            } if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                } S3.length()>1 S3.length() S3.length S3 1 {
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                } ch = S3.charAt(0) ch S3.charAt(0) S3.charAt S3 0 S3 = S3.substring(1,S3.length()) S3 S3.substring(1,S3.length()) S3.substring S3 1 S3.length() S3.length S3 if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                } S3.length()==1 S3.length() S3.length S3 1 {
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                } ch = S3.charAt(0) ch S3.charAt(0) S3.charAt S3 0 S3 = "" S3 "" {
                    ans = "C";
                    test = false;
                } ans = "C" ans "C" test = false test false System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        boolean test = true;
        String ans = "";
        char ch = 'a';
        
        while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        boolean test = true;
        String ans = "";
        char ch = 'a';
        
        while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        boolean test = true;
        String ans = "";
        char ch = 'a';
        
        while(test){
            if(ch == 'a'){
                if(S1.length()>1){
                    ch = S1.charAt(0);
                    S1 = S1.substring(1,S1.length());
                    //System.out.println(ch+":"+S1);
                }else if(S1.length()==1){
                    ch = S1.charAt(0);
                    S1 = "";
                    //System.out.println(ch+":"+S1);
                }else{
                    ans = "A";
                    test = false;
                }
            }else if(ch == 'b'){
                if(S2.length()>1){
                    ch = S2.charAt(0);
                    S2 = S2.substring(1,S2.length());
                    //System.out.println(ch+":"+S2);
                }else if(S2.length()==1){
                    ch = S2.charAt(0);
                    S2 = "";
                    //System.out.println(ch+":"+S2);
                }else{
                    ans = "B";
                    test = false;
                }
            }else{
                if(S3.length()>1){
                    ch = S3.charAt(0);
                    S3 = S3.substring(1,S3.length());
                    //System.out.println(ch+":"+S3);
                }else if(S3.length()==1){
                    ch = S3.charAt(0);
                    S3 = "";
                    //System.out.println(ch+":"+S3);
                }else{
                    ans = "C";
                    test = false;
                }
            }
        }
        System.out.println(ans);
    }
}
