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

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    }
} import java.util.*; util.* java public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    } main {
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String Sa = sc.next(); Sa sc.next() sc.next sc String Sb = sc.next(); Sb sc.next() sc.next sc String Sc = sc.next(); Sc sc.next() sc.next sc sc.close() sc.close sc int numA = Sa.length(); numA Sa.length() Sa.length Sa int numB = Sb.length(); numB Sb.length() Sb.length Sb int numC = Sc.length(); numC Sc.length() Sc.length Sc int countA = 0; countA 0 int countB = 0; countB 0 int countC = 0; countC 0 char turn = 'a'; turn 'a' while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        } true {
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        } if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            } turn == 'a' turn 'a' {
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            } if(countA == numA){
                    System.out.println('A');
                    break;
                } countA == numA countA numA {
                    System.out.println('A');
                    break;
                } System.out.println('A') System.out.println System.out System System.out 'A' break; turn = Sa.charAt(countA) turn Sa.charAt(countA) Sa.charAt Sa countA countA++ countA if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            } turn == 'b' turn 'b' {
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            } if(countB == numB){
                    System.out.println('B');
                    break;
                } countB == numB countB numB {
                    System.out.println('B');
                    break;
                } System.out.println('B') System.out.println System.out System System.out 'B' break; turn = Sb.charAt(countB) turn Sb.charAt(countB) Sb.charAt Sb countB countB++ countB if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            } turn == 'c' turn 'c' {
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            } if(countC == numC){
                    System.out.println('C');
                    break;
                } countC == numC countC numC {
                    System.out.println('C');
                    break;
                } System.out.println('C') System.out.println System.out System System.out 'C' break; turn = Sc.charAt(countC) turn Sc.charAt(countC) Sc.charAt Sc countC countC++ countC String args[] args public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    }
} public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    }
} Main
import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();
        sc.close();

        int numA = Sa.length();
        int numB = Sb.length();
        int numC = Sc.length();
        int countA = 0;
        int countB = 0;
        int countC = 0;
        
        char turn = 'a';

        while(true){
            if(turn == 'a'){
                if(countA == numA){
                    System.out.println('A');
                    break;
                }
                turn = Sa.charAt(countA);
                countA++;
            }
            if(turn == 'b'){
                if(countB == numB){
                    System.out.println('B');
                    break;
                }
                turn = Sb.charAt(countB);
                countB++;
            }
            if(turn == 'c'){
                if(countC == numC){
                    System.out.println('C');
                    break;
                }
                turn = Sc.charAt(countC);
                countC++;
            }    
        }
    }
}