import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int flg=0;
        
        char n = a.charAt(0);
        
        for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        }
        
   }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int flg=0;
        
        char n = a.charAt(0);
        
        for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        }
        
   }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int flg=0;
        
        char n = a.charAt(0);
        
        for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        }
        
   } main {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int flg=0;
        
        char n = a.charAt(0);
        
        for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        }
        
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc int flg=0; flg 0 char n = a.charAt(0); n a.charAt(0) a.charAt a 0 for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        } int i=0; int i=0; i 0 i<300 i 300 i++ i++ i {
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        } {
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        } if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            } n=='a' n 'a' {
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            } 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; n = a.charAt(0) n a.charAt(0) a.charAt a 0 a = a.substring(1,a.length()) a a.substring(1,a.length()) a.substring a 1 a.length() a.length a if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            } n=='b' n 'b' {
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            } 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; n = b.charAt(0) n b.charAt(0) b.charAt b 0 b = b.substring(1,b.length()) b b.substring(1,b.length()) b.substring b 1 b.length() b.length b if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            } n=='c' n 'c' {
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            } 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; n = c.charAt(0) n c.charAt(0) c.charAt c 0 c = c.substring(1,c.length()) c c.substring(1,c.length()) c.substring c 1 c.length() c.length c String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int flg=0;
        
        char n = a.charAt(0);
        
        for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        }
        
   }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int flg=0;
        
        char n = a.charAt(0);
        
        for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        }
        
   }
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int flg=0;
        
        char n = a.charAt(0);
        
        for(int i=0; i<300; i++){
            
            
            
            
            if(n=='a'){
                if(a.length()==0){
                    System.out.println("A");
                    return;
                }
                n = a.charAt(0);
                a = a.substring(1,a.length());
            }else if(n=='b'){
                if(b.length()==0){
                    System.out.println("B");
                    return;
                }
                n = b.charAt(0);
                b = b.substring(1,b.length());
            }else if(n=='c'){
                if(c.length()==0){
                    System.out.println("C");
                    return;
                }
                n = c.charAt(0);
                c = c.substring(1,c.length());
            }
        }
        
   }
}
