import java.util.Scanner;

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();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    }
}

/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