import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String alice = sc.next();
        String bob = sc.next();
        String charlie = sc.next();
        int a, b, c;
        a = b = c = 0;
        int turn = 1;
        while(true){
            if(turn == 1){
                if(a == alice.length()){
                    System.out.println('A');
                    break;
                }else{
                    if(alice.charAt(a) == 'a')
                        turn = 1;
                    else if(alice.charAt(a) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    a += 1;
                }
            }else if(turn == 2){
                if(b == bob.length()){
                    System.out.println('B');
                    break;
                }else{
                    if(bob.charAt(b) == 'a')
                        turn = 1;
                    else if(bob.charAt(b) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    b += 1;
                }
            }else{
                if(c == charlie.length()){
                    System.out.println('C');
                    break;
                }else{
                    if(charlie.charAt(c) == 'a')
                        turn = 1;
                    else if(charlie.charAt(c) == 'b')
                        turn = 2;
                    else
                        turn = 3;
                    c += 1;
                }
            }
        }
    }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz