import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    }

}

/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