import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String A=s.nextLine();
        String B=s.nextLine();
        String C=s.nextLine();
        Queue<Character> qA=new LinkedList<>();
        Queue<Character> qB=new LinkedList<>();
        Queue<Character> qC=new LinkedList<>();
        for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        }
        for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        }
        for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        }
        char curr_char='a';
        while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        }


    }
} import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String A=s.nextLine();
        String B=s.nextLine();
        String C=s.nextLine();
        Queue<Character> qA=new LinkedList<>();
        Queue<Character> qB=new LinkedList<>();
        Queue<Character> qC=new LinkedList<>();
        for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        }
        for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        }
        for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        }
        char curr_char='a';
        while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        }


    }
} Main public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String A=s.nextLine();
        String B=s.nextLine();
        String C=s.nextLine();
        Queue<Character> qA=new LinkedList<>();
        Queue<Character> qB=new LinkedList<>();
        Queue<Character> qC=new LinkedList<>();
        for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        }
        for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        }
        for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        }
        char curr_char='a';
        while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        }


    } main {
        Scanner s=new Scanner(System.in);
        String A=s.nextLine();
        String B=s.nextLine();
        String C=s.nextLine();
        Queue<Character> qA=new LinkedList<>();
        Queue<Character> qB=new LinkedList<>();
        Queue<Character> qC=new LinkedList<>();
        for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        }
        for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        }
        for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        }
        char curr_char='a';
        while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        }


    } Scanner s=new Scanner(System.in); s new Scanner(System.in) String A=s.nextLine(); A s.nextLine() s.nextLine s String B=s.nextLine(); B s.nextLine() s.nextLine s String C=s.nextLine(); C s.nextLine() s.nextLine s Queue<Character> qA=new LinkedList<>(); qA new LinkedList<>() Queue<Character> qB=new LinkedList<>(); qB new LinkedList<>() Queue<Character> qC=new LinkedList<>(); qC new LinkedList<>() for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        } int i=0; int i=0; i 0 i<A.length() i A.length() A.length A i++ i++ i {
            qA.add(A.charAt(i));
        } {
            qA.add(A.charAt(i));
        } qA.add(A.charAt(i)) qA.add qA A.charAt(i) A.charAt A i for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        } int i=0; int i=0; i 0 i<B.length() i B.length() B.length B i++ i++ i {
            qB.add(B.charAt(i));
        } {
            qB.add(B.charAt(i));
        } qB.add(B.charAt(i)) qB.add qB B.charAt(i) B.charAt B i for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        } int i=0; int i=0; i 0 i<C.length() i C.length() C.length C i++ i++ i {
            qC.add(C.charAt(i));
        } {
            qC.add(C.charAt(i));
        } qC.add(C.charAt(i)) qC.add qC C.charAt(i) C.charAt C i char curr_char='a'; curr_char 'a' while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        } !qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty() !qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty() !qA.isEmpty() qA.isEmpty() qA.isEmpty qA !qB.isEmpty() qB.isEmpty() qB.isEmpty qB !qC.isEmpty() qC.isEmpty() qC.isEmpty qC {
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        } if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            } curr_char=='a' curr_char 'a' {
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            } if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                } qA.isEmpty() qA.isEmpty qA {
                    System.out.println("A");
                    break;
                } System.out.println("A") System.out.println System.out System System.out "A" break; curr_char=qA.remove() curr_char qA.remove() qA.remove qA if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            } curr_char=='b' curr_char 'b' {
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            } if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                } qB.isEmpty() qB.isEmpty qB {
                    System.out.println("B");
                    break;
                } System.out.println("B") System.out.println System.out System System.out "B" break; curr_char=qB.remove() curr_char qB.remove() qB.remove qB if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            } curr_char=='c' curr_char 'c' {
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            } if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                } qC.isEmpty() qC.isEmpty qC {
                    System.out.println("C");
                    break;
                } System.out.println("C") System.out.println System.out System System.out "C" break; curr_char=qC.remove() curr_char qC.remove() qC.remove qC String[] args args public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String A=s.nextLine();
        String B=s.nextLine();
        String C=s.nextLine();
        Queue<Character> qA=new LinkedList<>();
        Queue<Character> qB=new LinkedList<>();
        Queue<Character> qC=new LinkedList<>();
        for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        }
        for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        }
        for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        }
        char curr_char='a';
        while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        }


    }
} public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String A=s.nextLine();
        String B=s.nextLine();
        String C=s.nextLine();
        Queue<Character> qA=new LinkedList<>();
        Queue<Character> qB=new LinkedList<>();
        Queue<Character> qC=new LinkedList<>();
        for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        }
        for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        }
        for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        }
        char curr_char='a';
        while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        }


    }
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        String A=s.nextLine();
        String B=s.nextLine();
        String C=s.nextLine();
        Queue<Character> qA=new LinkedList<>();
        Queue<Character> qB=new LinkedList<>();
        Queue<Character> qC=new LinkedList<>();
        for(int i=0;i<A.length();i++){
            qA.add(A.charAt(i));
        }
        for(int i=0;i<B.length();i++){
            qB.add(B.charAt(i));
        }
        for(int i=0;i<C.length();i++){
            qC.add(C.charAt(i));
        }
        char curr_char='a';
        while(!qA.isEmpty() || !qB.isEmpty() || !qC.isEmpty()){
            if(curr_char=='a'){
                if(qA.isEmpty()){
                    System.out.println("A");
                    break;
                }

                curr_char=qA.remove();
            }
            if(curr_char=='b'){
                if(qB.isEmpty()){
                    System.out.println("B");
                    break;
                }

                curr_char=qB.remove();
            }
            if(curr_char=='c'){
                if(qC.isEmpty()){
                    System.out.println("C");
                    break;
                }
                curr_char=qC.remove();
            }
        }


    }
}
