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 card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	}
}
/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