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

		char card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	}
} import java.util.Scanner; Scanner java.util 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();

		char card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	}
} 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();

		char card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);

		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();

		char card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String Sa = sc.next(); Sa sc.next() sc.next sc String Sb = sc.next(); Sb sc.next() sc.next sc String Sc = sc.next(); Sc sc.next() sc.next sc char card = Sa.charAt(0); card Sa.charAt(0) Sa.charAt Sa 0 Sa = Sa.substring(1, Sa.length()) Sa Sa.substring(1, Sa.length()) Sa.substring Sa 1 Sa.length() Sa.length Sa while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		} true {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		} if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			} card == 'a' card 'a' {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				} Sa.length() == 0 Sa.length() Sa.length Sa 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				} card = Sa.charAt(0) card Sa.charAt(0) Sa.charAt Sa 0 Sa = Sa.substring(1, Sa.length()) Sa Sa.substring(1, Sa.length()) Sa.substring Sa 1 Sa.length() Sa.length Sa if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			} card == 'b' card 'b' {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				} Sb.length() == 0 Sb.length() Sb.length Sb 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				} card = Sb.charAt(0) card Sb.charAt(0) Sb.charAt Sb 0 Sb = Sb.substring(1, Sb.length()) Sb Sb.substring(1, Sb.length()) Sb.substring Sb 1 Sb.length() Sb.length Sb {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			} if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				} Sc.length() == 0 Sc.length() Sc.length Sc 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				} card = Sc.charAt(0) card Sc.charAt(0) Sc.charAt Sc 0 Sc = Sc.substring(1, Sc.length()) Sc Sc.substring(1, Sc.length()) Sc.substring Sc 1 Sc.length() Sc.length Sc String[] args args 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();

		char card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	}
} 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();

		char card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	}
} Main
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();

		char card = Sa.charAt(0);
		Sa = Sa.substring(1, Sa.length());

		while (true) {

			if (card == 'a') {
				if (Sa.length() == 0) {
					System.out.println("A");
					break;
				} else {
					card = Sa.charAt(0);
					Sa = Sa.substring(1, Sa.length());
				}
			} else if (card == 'b') {
				if (Sb.length() == 0) {
					System.out.println("B");
					break;
				} else {
					card = Sb.charAt(0);
					Sb = Sb.substring(1, Sb.length());
				}
			} else {
				if (Sc.length() == 0) {
					System.out.println("C");
					break;
				} else {
					card = Sc.charAt(0);
					Sc = Sc.substring(1, Sc.length());
				}
			}
		}
	}
}