import java.util.*;

public class Main {    
    public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                                
         
        StringBuilder sA = new StringBuilder(sc.nextLine());
        StringBuilder sB = new StringBuilder(sc.nextLine());
        StringBuilder sC = new StringBuilder(sc.nextLine());
        
        Map<Character,StringBuilder> map = new HashMap<>();
        
        map.put('a',sA);
        map.put('b',sB);
        map.put('c',sC);

        char ch = sA.charAt(0);
         
        while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        }                        
        
    }            
} import java.util.*; util.* java public class Main {    
    public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                                
         
        StringBuilder sA = new StringBuilder(sc.nextLine());
        StringBuilder sB = new StringBuilder(sc.nextLine());
        StringBuilder sC = new StringBuilder(sc.nextLine());
        
        Map<Character,StringBuilder> map = new HashMap<>();
        
        map.put('a',sA);
        map.put('b',sB);
        map.put('c',sC);

        char ch = sA.charAt(0);
         
        while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        }                        
        
    }            
} Main public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                                
         
        StringBuilder sA = new StringBuilder(sc.nextLine());
        StringBuilder sB = new StringBuilder(sc.nextLine());
        StringBuilder sC = new StringBuilder(sc.nextLine());
        
        Map<Character,StringBuilder> map = new HashMap<>();
        
        map.put('a',sA);
        map.put('b',sB);
        map.put('c',sC);

        char ch = sA.charAt(0);
         
        while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        }                        
        
    } main {        
        Scanner sc = new Scanner(System.in);                                
         
        StringBuilder sA = new StringBuilder(sc.nextLine());
        StringBuilder sB = new StringBuilder(sc.nextLine());
        StringBuilder sC = new StringBuilder(sc.nextLine());
        
        Map<Character,StringBuilder> map = new HashMap<>();
        
        map.put('a',sA);
        map.put('b',sB);
        map.put('c',sC);

        char ch = sA.charAt(0);
         
        while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        }                        
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sA = new StringBuilder(sc.nextLine()); sA new StringBuilder(sc.nextLine()) StringBuilder sB = new StringBuilder(sc.nextLine()); sB new StringBuilder(sc.nextLine()) StringBuilder sC = new StringBuilder(sc.nextLine()); sC new StringBuilder(sc.nextLine()) Map<Character,StringBuilder> map = new HashMap<>(); map new HashMap<>() map.put('a',sA) map.put map 'a' sA map.put('b',sB) map.put map 'b' sB map.put('c',sC) map.put map 'c' sC char ch = sA.charAt(0); ch sA.charAt(0) sA.charAt sA 0 while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        } true {                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        } StringBuilder sb = map.get(ch); sb map.get(ch) map.get map ch if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           } sb.length() == 0 sb.length() sb.length sb 0 {
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           } System.out.println(String.valueOf(ch).toUpperCase()) System.out.println System.out System System.out String.valueOf(ch).toUpperCase() String.valueOf(ch).toUpperCase String.valueOf(ch) String.valueOf String ch return; ch = sb.charAt(0) ch sb.charAt(0) sb.charAt sb 0 sb.deleteCharAt(0) sb.deleteCharAt sb 0 String[] args args public class Main {    
    public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                                
         
        StringBuilder sA = new StringBuilder(sc.nextLine());
        StringBuilder sB = new StringBuilder(sc.nextLine());
        StringBuilder sC = new StringBuilder(sc.nextLine());
        
        Map<Character,StringBuilder> map = new HashMap<>();
        
        map.put('a',sA);
        map.put('b',sB);
        map.put('c',sC);

        char ch = sA.charAt(0);
         
        while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        }                        
        
    }            
} public class Main {    
    public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                                
         
        StringBuilder sA = new StringBuilder(sc.nextLine());
        StringBuilder sB = new StringBuilder(sc.nextLine());
        StringBuilder sC = new StringBuilder(sc.nextLine());
        
        Map<Character,StringBuilder> map = new HashMap<>();
        
        map.put('a',sA);
        map.put('b',sB);
        map.put('c',sC);

        char ch = sA.charAt(0);
         
        while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        }                        
        
    }            
} Main
import java.util.*;

public class Main {    
    public static void main(String[] args){        
        Scanner sc = new Scanner(System.in);                                
         
        StringBuilder sA = new StringBuilder(sc.nextLine());
        StringBuilder sB = new StringBuilder(sc.nextLine());
        StringBuilder sC = new StringBuilder(sc.nextLine());
        
        Map<Character,StringBuilder> map = new HashMap<>();
        
        map.put('a',sA);
        map.put('b',sB);
        map.put('c',sC);

        char ch = sA.charAt(0);
         
        while(true){                                  
           StringBuilder sb = map.get(ch);      
           if(sb.length() == 0){
                System.out.println(String.valueOf(ch).toUpperCase());   
                return;
           }           
           ch = sb.charAt(0);
           sb.deleteCharAt(0);                                                      
        }                        
        
    }            
}