import java.util.*;

public class Main {
	private static String[] cards;

	private static String winner(int player) {
		if(cards[player].length() == 0) {
			switch(player) {
				case 0:
					return "A";
				case 1:
					return "B";
				default:
					return "C";
			}
		} else {
			int nextPlayer;
			switch(cards[player].charAt(0)) {
				case 'a':
					nextPlayer = 0;
					break;
				case 'b':
					nextPlayer = 1;
					break;
				default:
					nextPlayer = 2;
					break;
			}
			cards[player] = cards[player].substring(1, cards[player].length());
			return winner(nextPlayer);
		}
	}

	public static void main(String[] args) {
		cards = new String[3];
		Scanner sc = new Scanner(System.in);
		for(int i = 0; i < 3; i++)
			cards[i] = sc.next();
		System.out.println(winner(0));
	}
}
/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