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));
	}
} import java.util.*; util.* java 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));
	}
} Main private static String[] cards; 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);
		}
	} winner {
		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);
		}
	} 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);
		} cards[player].length() == 0 cards[player].length() cards[player].length cards[player] cards player 0 {
			switch(player) {
				case 0:
					return "A";
				case 1:
					return "B";
				default:
					return "C";
			}
		} switch(player) {
				case 0:
					return "A";
				case 1:
					return "B";
				default:
					return "C";
			} player case 0: 0 case 0: return "A"; "A" case 1: 1 case 1: return "B"; "B" default: default: return "C"; "C" {
			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);
		} int nextPlayer; nextPlayer switch(cards[player].charAt(0)) {
				case 'a':
					nextPlayer = 0;
					break;
				case 'b':
					nextPlayer = 1;
					break;
				default:
					nextPlayer = 2;
					break;
			} cards[player].charAt(0) cards[player].charAt cards[player] cards player 0 case 'a': 'a' case 'a': nextPlayer = 0 nextPlayer 0 break; case 'b': 'b' case 'b': nextPlayer = 1 nextPlayer 1 break; default: default: nextPlayer = 2 nextPlayer 2 break; cards[player] = cards[player].substring(1, cards[player].length()) cards[player] cards player cards[player].substring(1, cards[player].length()) cards[player].substring cards[player] cards player 1 cards[player].length() cards[player].length cards[player] cards player return winner(nextPlayer); winner(nextPlayer) winner nextPlayer int player player 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));
	} main {
		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));
	} cards = new String[3] cards new String[3] 3 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) for(int i = 0; i < 3; i++)
			cards[i] = sc.next(); int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i cards[i] = sc.next(); cards[i] = sc.next() cards[i] cards i sc.next() sc.next sc System.out.println(winner(0)) System.out.println System.out System System.out winner(0) winner 0 String[] args args 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));
	}
} 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));
	}
} Main
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));
	}
}