import java.util.*;

public class Main {
  
        static StringBuilder a = new StringBuilder();
        static StringBuilder b = new StringBuilder();
        static StringBuilder c = new StringBuilder();
	
	public static void main(String[] args) {
      
		Scanner sc = new Scanner(System.in);   
      
        a.append(sc.next());
        b.append(sc.next());
        c.append(sc.next());
      
        char tmp = a.charAt(0);
        a.deleteCharAt(0);
      
        Main.nextTurn(tmp);
        
       
	} 
  
    public static void nextTurn(char card) {
        if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        }
    }
} import java.util.*; util.* java public class Main {
  
        static StringBuilder a = new StringBuilder();
        static StringBuilder b = new StringBuilder();
        static StringBuilder c = new StringBuilder();
	
	public static void main(String[] args) {
      
		Scanner sc = new Scanner(System.in);   
      
        a.append(sc.next());
        b.append(sc.next());
        c.append(sc.next());
      
        char tmp = a.charAt(0);
        a.deleteCharAt(0);
      
        Main.nextTurn(tmp);
        
       
	} 
  
    public static void nextTurn(char card) {
        if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        }
    }
} Main static StringBuilder a = new StringBuilder(); a new StringBuilder() static StringBuilder b = new StringBuilder(); b new StringBuilder() static StringBuilder c = new StringBuilder(); c new StringBuilder() public static void main(String[] args) {
      
		Scanner sc = new Scanner(System.in);   
      
        a.append(sc.next());
        b.append(sc.next());
        c.append(sc.next());
      
        char tmp = a.charAt(0);
        a.deleteCharAt(0);
      
        Main.nextTurn(tmp);
        
       
	} main {
      
		Scanner sc = new Scanner(System.in);   
      
        a.append(sc.next());
        b.append(sc.next());
        c.append(sc.next());
      
        char tmp = a.charAt(0);
        a.deleteCharAt(0);
      
        Main.nextTurn(tmp);
        
       
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) a.append(sc.next()) a.append a sc.next() sc.next sc b.append(sc.next()) b.append b sc.next() sc.next sc c.append(sc.next()) c.append c sc.next() sc.next sc char tmp = a.charAt(0); tmp a.charAt(0) a.charAt a 0 a.deleteCharAt(0) a.deleteCharAt a 0 Main.nextTurn(tmp) Main.nextTurn Main tmp String[] args args public static void nextTurn(char card) {
        if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        }
    } nextTurn {
        if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        }
    } if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } card == 'a' card 'a' {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } if(a.length() == 0) {
             System.out.println("A");
             return;
           } a.length() == 0 a.length() a.length a 0 {
             System.out.println("A");
             return;
           } System.out.println("A") System.out.println System.out System System.out "A" return; char tmp = a.charAt(0); tmp a.charAt(0) a.charAt a 0 a.deleteCharAt(0) a.deleteCharAt a 0 Main.nextTurn(tmp) Main.nextTurn Main tmp if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } card == 'b' card 'b' {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } if(b.length() == 0) {
             System.out.println("B");
             return;
           } b.length() == 0 b.length() b.length b 0 {
             System.out.println("B");
             return;
           } System.out.println("B") System.out.println System.out System System.out "B" return; char tmp = b.charAt(0); tmp b.charAt(0) b.charAt b 0 b.deleteCharAt(0) b.deleteCharAt b 0 Main.nextTurn(tmp) Main.nextTurn Main tmp if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } card == 'c' card 'c' {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } if(c.length() == 0) {
             System.out.println("C");
             return;
           } c.length() == 0 c.length() c.length c 0 {
             System.out.println("C");
             return;
           } System.out.println("C") System.out.println System.out System System.out "C" return; char tmp = c.charAt(0); tmp c.charAt(0) c.charAt c 0 c.deleteCharAt(0) c.deleteCharAt c 0 Main.nextTurn(tmp) Main.nextTurn Main tmp char card card public class Main {
  
        static StringBuilder a = new StringBuilder();
        static StringBuilder b = new StringBuilder();
        static StringBuilder c = new StringBuilder();
	
	public static void main(String[] args) {
      
		Scanner sc = new Scanner(System.in);   
      
        a.append(sc.next());
        b.append(sc.next());
        c.append(sc.next());
      
        char tmp = a.charAt(0);
        a.deleteCharAt(0);
      
        Main.nextTurn(tmp);
        
       
	} 
  
    public static void nextTurn(char card) {
        if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        }
    }
} public class Main {
  
        static StringBuilder a = new StringBuilder();
        static StringBuilder b = new StringBuilder();
        static StringBuilder c = new StringBuilder();
	
	public static void main(String[] args) {
      
		Scanner sc = new Scanner(System.in);   
      
        a.append(sc.next());
        b.append(sc.next());
        c.append(sc.next());
      
        char tmp = a.charAt(0);
        a.deleteCharAt(0);
      
        Main.nextTurn(tmp);
        
       
	} 
  
    public static void nextTurn(char card) {
        if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        }
    }
} Main
import java.util.*;

public class Main {
  
        static StringBuilder a = new StringBuilder();
        static StringBuilder b = new StringBuilder();
        static StringBuilder c = new StringBuilder();
	
	public static void main(String[] args) {
      
		Scanner sc = new Scanner(System.in);   
      
        a.append(sc.next());
        b.append(sc.next());
        c.append(sc.next());
      
        char tmp = a.charAt(0);
        a.deleteCharAt(0);
      
        Main.nextTurn(tmp);
        
       
	} 
  
    public static void nextTurn(char card) {
        if (card == 'a') {
           if(a.length() == 0) {
             System.out.println("A");
             return;
           }
          
           //System.out.println("Turn A"); //最後に消す
           char tmp = a.charAt(0);
           a.deleteCharAt(0);
                     
           Main.nextTurn(tmp);
          
        } else if (card == 'b') {
           if(b.length() == 0) {
             System.out.println("B");
             return;
           }
          
           //System.out.println("Turn B"); //最後に消す
           char tmp = b.charAt(0);
           b.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        } else if (card == 'c') {
           if(c.length() == 0) {
             System.out.println("C");
             return;
           }
          
           //System.out.println("Turn C"); //最後に消す
           char tmp = c.charAt(0);
           c.deleteCharAt(0);
          
           Main.nextTurn(tmp);
        }
    }
}