import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

	} main {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String sa = scan.next(); sa scan.next() scan.next scan String sb = scan.next(); sb scan.next() scan.next scan String sc = scan.next(); sc scan.next() scan.next scan char flag = 'a'; flag 'a' int a_count = 0 a_count 0 b_count = 0 b_count 0 c_count = 0; c_count 0 while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		} true {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		} if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			} flag == 'a' flag 'a' {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			} if (a_count == sa.length()) {
					System.out.print("A");
					break;
				} a_count == sa.length() a_count sa.length() sa.length sa {
					System.out.print("A");
					break;
				} System.out.print("A") System.out.print System.out System System.out "A" break; flag = sa.charAt(a_count) flag sa.charAt(a_count) sa.charAt sa a_count a_count++ a_count if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			} flag == 'b' flag 'b' {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			} if (b_count == sb.length()) {
					System.out.print("B");
					break;
				} b_count == sb.length() b_count sb.length() sb.length sb {
					System.out.print("B");
					break;
				} System.out.print("B") System.out.print System.out System System.out "B" break; flag = sb.charAt(b_count) flag sb.charAt(b_count) sb.charAt sb b_count b_count++ b_count if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			} flag == 'c' flag 'c' {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			} if (c_count == sc.length()) {
					System.out.print("C");
					break;
				} c_count == sc.length() c_count sc.length() sc.length sc {
					System.out.print("C");
					break;
				} System.out.print("C") System.out.print System.out System System.out "C" break; flag = sc.charAt(c_count) flag sc.charAt(c_count) sc.charAt sc c_count c_count++ c_count String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

	}
} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String sa = scan.next();
		String sb = scan.next();
		String sc = scan.next();

		char flag = 'a';

		int a_count = 0, b_count = 0, c_count = 0;

		while (true) {
			if (flag == 'a') {
				if (a_count == sa.length()) {
					System.out.print("A");
					break;
				}
				flag = sa.charAt(a_count);
				a_count++;
			}

			if (flag == 'b') {
				if (b_count == sb.length()) {
					System.out.print("B");
					break;
				}
				flag = sb.charAt(b_count);
				b_count++;
			}

			if (flag == 'c') {
				if (c_count == sc.length()) {
					System.out.print("C");
					break;
				}
				flag = sc.charAt(c_count);
				c_count++;
			}
		}

	}
}
