import java.util.*;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner sc  = new Scanner(System.in);

		int o= 0 ,p = 0,q = 0;
		long a = 0, b = 0, c = 0;
		char ch ;
		String str="";
		
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        ch = c1[o];
        
        while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        }
        
        System.out.print(str);
        System.out.println();
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
 
		Scanner sc  = new Scanner(System.in);

		int o= 0 ,p = 0,q = 0;
		long a = 0, b = 0, c = 0;
		char ch ;
		String str="";
		
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        ch = c1[o];
        
        while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        }
        
        System.out.print(str);
        System.out.println();
	}
} Main public static void main(String[] args) {
 
		Scanner sc  = new Scanner(System.in);

		int o= 0 ,p = 0,q = 0;
		long a = 0, b = 0, c = 0;
		char ch ;
		String str="";
		
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        ch = c1[o];
        
        while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        }
        
        System.out.print(str);
        System.out.println();
	} main {
 
		Scanner sc  = new Scanner(System.in);

		int o= 0 ,p = 0,q = 0;
		long a = 0, b = 0, c = 0;
		char ch ;
		String str="";
		
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        ch = c1[o];
        
        while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        }
        
        System.out.print(str);
        System.out.println();
	} Scanner sc  = new Scanner(System.in); sc new Scanner(System.in) int o= 0 o 0 p = 0 p 0 q = 0; q 0 long a = 0 a 0 b = 0 b 0 c = 0; c 0 char ch ; ch String str=""; str "" 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 char[] c1 = s1.toCharArray(); c1 s1.toCharArray() s1.toCharArray s1 char[] c2 = s2.toCharArray(); c2 s2.toCharArray() s2.toCharArray s2 char[] c3 = s3.toCharArray(); c3 s3.toCharArray() s3.toCharArray s3 ch = c1[o] ch c1[o] c1 o while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        } true {
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        } if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            } ch=='a' ch 'a' {
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            } if(o==s1.length()){
                    str = "A";
                    break;
                } o==s1.length() o s1.length() s1.length s1 {
                    str = "A";
                    break;
                } str = "A" str "A" break; ch=c1[o] ch c1[o] c1 o o++ o if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            } ch=='b' ch 'b' {
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            } if(p==s2.length()){
                    str = "B";
                    break;
                } p==s2.length() p s2.length() s2.length s2 {
                    str = "B";
                    break;
                } str = "B" str "B" break; ch=c2[p] ch c2[p] c2 p p++ p if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            } ch=='c' ch 'c' {
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            } if(q==s3.length()){
                    str = "C";
                    break;
                } q==s3.length() q s3.length() s3.length s3 {
                    str = "C";
                    break;
                } str = "C" str "C" break; ch=c3[q] ch c3[q] c3 q q++ q System.out.print(str) System.out.print System.out System System.out str System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) {
 
		Scanner sc  = new Scanner(System.in);

		int o= 0 ,p = 0,q = 0;
		long a = 0, b = 0, c = 0;
		char ch ;
		String str="";
		
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        ch = c1[o];
        
        while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        }
        
        System.out.print(str);
        System.out.println();
	}
} public class Main {
	public static void main(String[] args) {
 
		Scanner sc  = new Scanner(System.in);

		int o= 0 ,p = 0,q = 0;
		long a = 0, b = 0, c = 0;
		char ch ;
		String str="";
		
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        ch = c1[o];
        
        while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        }
        
        System.out.print(str);
        System.out.println();
	}
} Main
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
 
		Scanner sc  = new Scanner(System.in);

		int o= 0 ,p = 0,q = 0;
		long a = 0, b = 0, c = 0;
		char ch ;
		String str="";
		
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        char[] c3 = s3.toCharArray();
        
        ch = c1[o];
        
        while(true){
            
            if(ch=='a'){
                if(o==s1.length()){
                    str = "A";
                    break;
                }
                 ch=c1[o];
                 o++;
            }else if(ch=='b'){
              if(p==s2.length()){
                    str = "B";
                    break;
                }
                 ch=c2[p];
                 p++;
            }else if(ch=='c'){
                 if(q==s3.length()){
                    str = "C";
                    break;
                }
                 ch=c3[q];
                 q++;
            }
        }
        
        System.out.print(str);
        System.out.println();
	}
}