import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String nextTern = "a";
		while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		}

	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String nextTern = "a";
		while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		}

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String nextTern = "a";
		while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		}

	} main {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String nextTern = "a";
		while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc String nextTern = "a"; nextTern "a" while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		} a.length() > 0 || b.length() > 0 || c.length() > 0 a.length() > 0 || b.length() > 0 || c.length() > 0 a.length() > 0 a.length() a.length a 0 b.length() > 0 b.length() b.length b 0 c.length() > 0 c.length() c.length c 0 {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		} if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			} nextTern.equals("a") nextTern.equals nextTern "a" {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} if (a.length() == 0) {
					System.out.println("A");
					break;
				} a.length() == 0 a.length() a.length a 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; nextTern = a.substring(0, 1) nextTern a.substring(0, 1) a.substring a 0 1 if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				} a.length() > 1 a.length() a.length a 1 {
					a = a.substring(1);
				} a = a.substring(1) a a.substring(1) a.substring a 1 {
					a = "";
				} a = "" a "" if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			} nextTern.equals("b") nextTern.equals nextTern "b" {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} if (b.length() == 0) {
					System.out.println("B");
					break;
				} b.length() == 0 b.length() b.length b 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; nextTern = b.substring(0, 1) nextTern b.substring(0, 1) b.substring b 0 1 if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				} b.length() > 1 b.length() b.length b 1 {
					b = b.substring(1);
				} b = b.substring(1) b b.substring(1) b.substring b 1 {
					b = "";
				} b = "" b "" {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			} if (c.length() == 0) {
					System.out.println("C");
					break;
				} c.length() == 0 c.length() c.length c 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; nextTern = c.substring(0, 1) nextTern c.substring(0, 1) c.substring c 0 1 if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				} c.length() > 1 c.length() c.length c 1 {
					c = c.substring(1);
				} c = c.substring(1) c c.substring(1) c.substring c 1 {
					c = "";
				} c = "" c "" String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String nextTern = "a";
		while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		}

	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String nextTern = "a";
		while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		}

	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String nextTern = "a";
		while (a.length() > 0 || b.length() > 0 || c.length() > 0) {
			if (nextTern.equals("a")) {
				if (a.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTern = a.substring(0, 1);
				if (a.length() > 1) {
					a = a.substring(1);
				} else {
					a = "";
				}

			} else if (nextTern.equals("b")) {
				if (b.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTern = b.substring(0, 1);
				if (b.length() > 1) {
					b = b.substring(1);
				} else {
					b = "";
				}
			} else {
				if (c.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTern = c.substring(0, 1);
				if (c.length() > 1) {
					c = c.substring(1);
				} else {
					c = "";
				}
			}
		}

	}

}