import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turn=0;
        int turntmp;
        String[] cards=new String[3];
        for(int i=0;i<3;i++){
            cards[i]=sc.next();
        }
        String[] outputs={"A","B","C"};
        while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        }

    }
    
 
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turn=0;
        int turntmp;
        String[] cards=new String[3];
        for(int i=0;i<3;i++){
            cards[i]=sc.next();
        }
        String[] outputs={"A","B","C"};
        while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        }

    }
    
 
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turn=0;
        int turntmp;
        String[] cards=new String[3];
        for(int i=0;i<3;i++){
            cards[i]=sc.next();
        }
        String[] outputs={"A","B","C"};
        while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        }

    } main {
        Scanner sc = new Scanner(System.in);
        int turn=0;
        int turntmp;
        String[] cards=new String[3];
        for(int i=0;i<3;i++){
            cards[i]=sc.next();
        }
        String[] outputs={"A","B","C"};
        while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int turn=0; turn 0 int turntmp; turntmp String[] cards=new String[3]; cards new String[3] 3 for(int i=0;i<3;i++){
            cards[i]=sc.next();
        } int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
            cards[i]=sc.next();
        } {
            cards[i]=sc.next();
        } cards[i]=sc.next() cards[i] cards i sc.next() sc.next sc String[] outputs={"A","B","C"}; outputs {"A","B","C"} "A" "B" "C" while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        } true {
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        } if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            } cards[turn].length()==0 cards[turn].length() cards[turn].length cards[turn] cards turn 0 {
                System.out.println(outputs[turn]);
                return;
            } System.out.println(outputs[turn]) System.out.println System.out System System.out outputs[turn] outputs turn return; turntmp=turn turntmp turn turn=(int)cards[turn].charAt(0)-97 turn (int)cards[turn].charAt(0)-97 (int)cards[turn].charAt(0) cards[turn].charAt cards[turn] cards turn 0 97 cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length()) cards[turntmp] cards turntmp cards[turntmp].substring(1,cards[turntmp].length()) cards[turntmp].substring cards[turntmp] cards turntmp 1 cards[turntmp].length() cards[turntmp].length cards[turntmp] cards turntmp String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turn=0;
        int turntmp;
        String[] cards=new String[3];
        for(int i=0;i<3;i++){
            cards[i]=sc.next();
        }
        String[] outputs={"A","B","C"};
        while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        }

    }
    
 
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turn=0;
        int turntmp;
        String[] cards=new String[3];
        for(int i=0;i<3;i++){
            cards[i]=sc.next();
        }
        String[] outputs={"A","B","C"};
        while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        }

    }
    
 
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int turn=0;
        int turntmp;
        String[] cards=new String[3];
        for(int i=0;i<3;i++){
            cards[i]=sc.next();
        }
        String[] outputs={"A","B","C"};
        while(true){
            if(cards[turn].length()==0){
                System.out.println(outputs[turn]);
                return;
            }
            turntmp=turn;
            turn=(int)cards[turn].charAt(0)-97;
            cards[turntmp]=cards[turntmp].substring(1,cards[turntmp].length());
        }

    }
    
 
}