import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String A = br.readLine();
		String B = br.readLine();
		String C = br.readLine();
		
		int Ai = 0;
		int Bi = 0;
		int Ci = 0;
		
		int Al = A.length();
		int Bl = B.length();
		int Cl = C.length();
		
		char turn = A.charAt(Ai++);
		while(true){
			if(turn == 'a'){
				if(Ai == Al){
					System.out.println('A');
					break;
				}
				turn = A.charAt(Ai++);
			} else if(turn == 'b'){
				if(Bi == Bl){
					System.out.println('B');
					break;
				}
				turn = B.charAt(Bi++);
			} else if(turn == 'c'){
				if(Ci == Cl){
					System.out.println('C');
					break;
				}
				turn = C.charAt(Ci++);
			}
		}
		
	}
}

/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