import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char x = a.charAt(0);
        int cnta = 1;
        int cntb = 0;
        int cntc = 0;
        while (true) {
            if (x == 'a') {
                try {
                    x = a.charAt(cnta);
                } catch (Exception e) {
                    System.out.println("A");
                    System.exit(0);
                }
                cnta++;
            } else if (x == 'b') {
                try {
                    x = b.charAt(cntb);
                } catch (Exception e) {
                    System.out.println("B");
                    System.exit(0);
                }
                cntb++;
            } else {
                try {
                    x = c.charAt(cntc);
                } catch (Exception e) {
                    System.out.println("C");
                    System.exit(0);
                }
                cntc++;
            }
        }
    }
}

/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