import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    }
    
    static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    }
    
    static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    }
    
    static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    }
    
    static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    }
    
    static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    }
    
    static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    } main {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String a = scan.next(); a scan.next() scan.next scan String b = scan.next(); b scan.next() scan.next scan String c = scan.next(); c scan.next() scan.next scan int aturn = 0; aturn 0 int bturn = 0; bturn 0 int cturn = 0; cturn 0 char check = 'a'; check 'a' while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        } true {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        } switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            } check case 'a': 'a' case 'a': check = NextA(aturn,a) check NextA(aturn,a) NextA aturn a aturn++ aturn break; case 'b': 'b' case 'b': check = NextB(bturn,b) check NextB(bturn,b) NextB bturn b bturn++ bturn break; case 'c': 'c' case 'c': check = NextC(cturn,c) check NextC(cturn,c) NextC cturn c cturn++ cturn break; default: default: return; String[] args args static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    } NextA {
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    } if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        } aturn == a.length() aturn a.length() a.length a {
            System.out.println("A");
            return 'z';
        } System.out.println("A") System.out.println System.out System System.out "A" return 'z'; 'z' {
            return a.charAt(aturn);
        } return a.charAt(aturn); a.charAt(aturn) a.charAt a aturn int aturn aturn String a a static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    } NextB {
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    } if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        } bturn == b.length() bturn b.length() b.length b {
            System.out.println("B");
            return 'z';
        } System.out.println("B") System.out.println System.out System System.out "B" return 'z'; 'z' {
            return b.charAt(bturn);
        } return b.charAt(bturn); b.charAt(bturn) b.charAt b bturn int bturn bturn String b b static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    } NextC {
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    } if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        } cturn == c.length() cturn c.length() c.length c {
            System.out.println("C");
            return 'z';
        } System.out.println("C") System.out.println System.out System System.out "C" return 'z'; 'z' {
            return c.charAt(cturn);
        } return c.charAt(cturn); c.charAt(cturn) c.charAt c cturn int cturn cturn String c c public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    }
    
    static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    }
    
    static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    }
    
    static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    }
    
    static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    }
    
    static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    }
    
    static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    }
    
    static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    }
    
    static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    }
    
    static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    }
}