import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	}

}

/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