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();

		int a = 0;
		int b = 0;
		int c = 0;
		int flag = -1;
		String A[] = Sa.split("");
		String B[] = Sb.split("");
		String C[] = Sc.split("");
		String str = "X";

		while(true){
			String X[];
			int x;
			if(flag == -1){
				X = A;
				if(A.length == a){
					str = "A";
				}
				x = a;
				a++;
				//System.out.println("a");
			}else if(flag == 0){
				X = B;
				if(B.length == b){
					str = "B";
				}
				x = b;
				b++;
				//System.out.println("b");
			}else{
				X = C;
				if(C.length == c){
					str = "C";
				}
				x = c;
				c++;
				//System.out.println("c");
			}//ここでlengthと同じになる

			if(!str.equals("X")){
				break;
			}

			if(X[x].equals("a")){
				flag = -1;
			}else if(X[x].equals("b")){
				flag = 0;
			}else{
				flag = 1;
			}

			//System.out.println(X + ":" + x);
		}

		System.out.println(str);
	}
}
/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