import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s_a = in.nextLine();
		String s_b = in.nextLine();
		String s_c = in.nextLine();

		int a = 0;
		int b = 0;
		int c = 0;


		char currentChar = 'a';
		while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		}

	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s_a = in.nextLine();
		String s_b = in.nextLine();
		String s_c = in.nextLine();

		int a = 0;
		int b = 0;
		int c = 0;


		char currentChar = 'a';
		while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		}

	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s_a = in.nextLine();
		String s_b = in.nextLine();
		String s_c = in.nextLine();

		int a = 0;
		int b = 0;
		int c = 0;


		char currentChar = 'a';
		while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		}

	} main {
		Scanner in = new Scanner(System.in);
		String s_a = in.nextLine();
		String s_b = in.nextLine();
		String s_c = in.nextLine();

		int a = 0;
		int b = 0;
		int c = 0;


		char currentChar = 'a';
		while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		}

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) String s_a = in.nextLine(); s_a in.nextLine() in.nextLine in String s_b = in.nextLine(); s_b in.nextLine() in.nextLine in String s_c = in.nextLine(); s_c in.nextLine() in.nextLine in int a = 0; a 0 int b = 0; b 0 int c = 0; c 0 char currentChar = 'a'; currentChar 'a' while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		} true {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		} if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							} currentChar == 'a' currentChar 'a' {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} if (a == s_a.length()) {
					System.out.println('A');
					break;
				} a == s_a.length() a s_a.length() s_a.length s_a {
					System.out.println('A');
					break;
				} System.out.println('A') System.out.println System.out System System.out 'A' break; currentChar = s_a.charAt(a) currentChar s_a.charAt(a) s_a.charAt s_a a a++ a if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							} currentChar=='b' currentChar 'b' {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} if(b==s_b.length()) {
					System.out.println('B');
					break;
				} b==s_b.length() b s_b.length() s_b.length s_b {
					System.out.println('B');
					break;
				} System.out.println('B') System.out.println System.out System System.out 'B' break; currentChar = s_b.charAt(b) currentChar s_b.charAt(b) s_b.charAt s_b b b++ b if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							} currentChar=='c' currentChar 'c' {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							} if (c == s_c.length()) {
					System.out.println('C');
					break;
				} c == s_c.length() c s_c.length() s_c.length s_c {
					System.out.println('C');
					break;
				} System.out.println('C') System.out.println System.out System System.out 'C' break; currentChar = s_c.charAt(c) currentChar s_c.charAt(c) s_c.charAt s_c c c++ c String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s_a = in.nextLine();
		String s_b = in.nextLine();
		String s_c = in.nextLine();

		int a = 0;
		int b = 0;
		int c = 0;


		char currentChar = 'a';
		while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		}

	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s_a = in.nextLine();
		String s_b = in.nextLine();
		String s_c = in.nextLine();

		int a = 0;
		int b = 0;
		int c = 0;


		char currentChar = 'a';
		while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		}

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s_a = in.nextLine();
		String s_b = in.nextLine();
		String s_c = in.nextLine();

		int a = 0;
		int b = 0;
		int c = 0;


		char currentChar = 'a';
		while (true) {
			if (currentChar == 'a') {
				if (a == s_a.length()) {
					System.out.println('A');
					break;
				}
				currentChar = s_a.charAt(a);
				a++;

			} else if(currentChar=='b') {
				if(b==s_b.length()) {
					System.out.println('B');
					break;
				}
				currentChar = s_b.charAt(b);
				b++;

			} else if(currentChar=='c') {
				if (c == s_c.length()) {
					System.out.println('C');
					break;
				}
				currentChar = s_c.charAt(c);
				c++;
							}
		}

	}
}
