import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String x = in.nextLine();
		String y = in.nextLine();
		String z = in.nextLine();
		String m = "A";
		int flag = 1;
		while (1==1) {
			
			if (flag == 1) {
				int l = x.length();
				if (l == 0) {
					m = "A";
					break;
				}
				char c = x.charAt(0);

				x = x.substring(1, l);
				flag = getFlag(c);
			} else if (flag == 2) {
				int l = y.length();
				if (l == 0) {
					m = "B";
					break;
				}
				char c = y.charAt(0);

				y = y.substring(1, y.length());
				flag = getFlag(c);
			} else {
				int l = z.length();
				if (l == 0) {
					m = "C";
					break;
				}
				char c = z.charAt(0);

				z = z.substring(1, z.length());
				flag = getFlag(c);
			}
		}
		System.out.println(m);
	}

	public static int getFlag(char c) {
		if (c == 'a') {
			return 1;
		} else if (c == 'b') {
			return 2;
		} else {
			return 3;
		}
	}
}

/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