import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

	}
}

/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