import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   } main {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String Sa =sc.nextLine(); Sa sc.nextLine() sc.nextLine sc String Sb =sc.nextLine(); Sb sc.nextLine() sc.nextLine sc String Sc =sc.nextLine(); Sc sc.nextLine() sc.nextLine sc String sptA[]=Sa.split(""); sptA Sa.split("") Sa.split Sa "" String sptB[]=Sb.split(""); sptB Sb.split("") Sb.split Sb "" String sptC[]=Sc.split(""); sptC Sc.split("") Sc.split Sc "" String next="a"; next "a" int i=0; i 0 int j=0; j 0 int k=0; k 0 while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        } true {
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        } if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            } next.equals("a") next.equals next "a" {
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            } if(i==sptA.length){
                    System.out.println("A");
                    return;
                } i==sptA.length i sptA.length sptA sptA.length {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; next=sptA[i] next sptA[i] sptA i i++ i if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            } next.equals("b") next.equals next "b" {
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            } if(j==sptB.length){
                    System.out.println("B");
                    return;
                } j==sptB.length j sptB.length sptB sptB.length {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; next=sptB[j] next sptB[j] sptB j j++ j if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            } next.equals("c") next.equals next "c" {
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            } if(k==sptC.length){
                    System.out.println("C");
                    return;
                } k==sptC.length k sptC.length sptC sptC.length {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; next=sptC[k] next sptC[k] sptC k k++ k String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   }
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa =sc.nextLine();
        String Sb =sc.nextLine();
        String Sc =sc.nextLine();
        
        String sptA[]=Sa.split("");
        String sptB[]=Sb.split("");
        String sptC[]=Sc.split("");
        
        String next="a";
        
        int i=0;
        int j=0;
        int k=0;
        
        while(true){
            if(next.equals("a")){
                if(i==sptA.length){
                    System.out.println("A");
                    return;
                }
                next=sptA[i];
                i++;
            }
            
            if(next.equals("b")){
                if(j==sptB.length){
                    System.out.println("B");
                    return;
                }
                next=sptB[j];
                j++;
            }
            
            if(next.equals("c")){
                if(k==sptC.length){
                    System.out.println("C");
                    return;
                }
                next=sptC[k];
                k++;
            }
            
        }
        
   }
}
