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();
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz