import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        String[] str=new String[3];
        int[] length=new int[3];
        int i=0,j=0;

        for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        }
        int a=0,b=0,c=0;
        char work;
        work=str[0].charAt(0);
        length[0]--;
        a++;

        while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        }
    
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        String[] str=new String[3];
        int[] length=new int[3];
        int i=0,j=0;

        for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        }
        int a=0,b=0,c=0;
        char work;
        work=str[0].charAt(0);
        length[0]--;
        a++;

        while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        }
    
    }
} Main public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        String[] str=new String[3];
        int[] length=new int[3];
        int i=0,j=0;

        for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        }
        int a=0,b=0,c=0;
        char work;
        work=str[0].charAt(0);
        length[0]--;
        a++;

        while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        }
    
    } main {
        Scanner scan=new Scanner(System.in);
        String[] str=new String[3];
        int[] length=new int[3];
        int i=0,j=0;

        for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        }
        int a=0,b=0,c=0;
        char work;
        work=str[0].charAt(0);
        length[0]--;
        a++;

        while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        }
    
    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) String[] str=new String[3]; str new String[3] 3 int[] length=new int[3]; length new int[3] 3 int i=0 i 0 j=0; j 0 for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        } i=0; i=0 i 0 i<3 i 3 i++ i++ i {
            str[i]=scan.next();
            length[i]=str[i].length();
        } {
            str[i]=scan.next();
            length[i]=str[i].length();
        } str[i]=scan.next() str[i] str i scan.next() scan.next scan length[i]=str[i].length() length[i] length i str[i].length() str[i].length str[i] str i int a=0 a 0 b=0 b 0 c=0; c 0 char work; work work=str[0].charAt(0) work str[0].charAt(0) str[0].charAt str[0] str 0 0 length[0]-- length[0] length 0 a++ a while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        } 1==1 1 1 {
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        } if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            } work=='a' work 'a' {
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            } if(length[0]==0){
                    System.out.println("A");
                    return;
                } length[0]==0 length[0] length 0 0 {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; work=str[0].charAt(a) work str[0].charAt(a) str[0].charAt str[0] str 0 a length[0]-- length[0] length 0 a++ a if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            } work=='b' work 'b' {
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            } if(length[1]==0){
                    System.out.println("B");
                    return;
                } length[1]==0 length[1] length 1 0 {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; work=str[1].charAt(b) work str[1].charAt(b) str[1].charAt str[1] str 1 b length[1]-- length[1] length 1 b++ b if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            } work=='c' work 'c' {
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            } if(length[2]==0){
                    System.out.println("C");
                    return;
                } length[2]==0 length[2] length 2 0 {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; work=str[2].charAt(c) work str[2].charAt(c) str[2].charAt str[2] str 2 c length[2]-- length[2] length 2 c++ c String args[] args public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        String[] str=new String[3];
        int[] length=new int[3];
        int i=0,j=0;

        for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        }
        int a=0,b=0,c=0;
        char work;
        work=str[0].charAt(0);
        length[0]--;
        a++;

        while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        }
    
    }
} public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        String[] str=new String[3];
        int[] length=new int[3];
        int i=0,j=0;

        for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        }
        int a=0,b=0,c=0;
        char work;
        work=str[0].charAt(0);
        length[0]--;
        a++;

        while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        }
    
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        String[] str=new String[3];
        int[] length=new int[3];
        int i=0,j=0;

        for(i=0;i<3;i++){
            str[i]=scan.next();
            length[i]=str[i].length();
        }
        int a=0,b=0,c=0;
        char work;
        work=str[0].charAt(0);
        length[0]--;
        a++;

        while(1==1){
            if(work=='a'){
                if(length[0]==0){
                    System.out.println("A");
                    return;
                }
                work=str[0].charAt(a);
                length[0]--;
                a++;
            }
            else if(work=='b'){
                if(length[1]==0){
                    System.out.println("B");
                    return;
                }
                work=str[1].charAt(b);
                length[1]--;
                b++;
            }
            else if(work=='c'){
                if(length[2]==0){
                    System.out.println("C");
                    return;
                }
                work=str[2].charAt(c);
                length[2]--;
                c++;
            }
        }
    
    }
}