import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	}

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

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	} main {
		Scanner scan = new Scanner(System.in);

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String sa = scan.nextLine(); sa scan.nextLine() scan.nextLine scan String sb = scan.nextLine(); sb scan.nextLine() scan.nextLine scan String sc = scan.nextLine(); sc scan.nextLine() scan.nextLine scan int i = 0; i 0 int j = 0; j 0 int k = 0; k 0 List<String> a = new ArrayList<String>(); a new ArrayList<String>() List<String> b = new ArrayList<String>(); b new ArrayList<String>() List<String> c = new ArrayList<String>(); c new ArrayList<String>() for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		} i = 0; i = 0 i 0 i < sa.length() i sa.length() sa.length sa i++ i++ i {
			a.add(sa.charAt(i) + "");
		} {
			a.add(sa.charAt(i) + "");
		} a.add(sa.charAt(i) + "") a.add a sa.charAt(i) + "" sa.charAt(i) sa.charAt sa i "" for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		} j = 0; j = 0 j 0 j < sb.length() j sb.length() sb.length sb j++ j++ j {
			b.add(sb.charAt(j) + "");
		} {
			b.add(sb.charAt(j) + "");
		} b.add(sb.charAt(j) + "") b.add b sb.charAt(j) + "" sb.charAt(j) sb.charAt sb j "" for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		} k = 0; k = 0 k 0 k < sc.length() k sc.length() sc.length sc k++ k++ k {
			c.add(sc.charAt(k) + "");
		} {
			c.add(sc.charAt(k) + "");
		} c.add(sc.charAt(k) + "") c.add c sc.charAt(k) + "" sc.charAt(k) sc.charAt sc k "" String ha = "a"; ha "a" i = 1 i 1 for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		} ; {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		} {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		} if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			} ha.equals("a") ha.equals ha "a" {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} if (a.size() == 0) {
					System.out.println("A");
					break;
				} a.size() == 0 a.size() a.size a 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; ha = a.get(0) ha a.get(0) a.get a 0 a.remove(0) a.remove a 0 if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			} ha.equals("b") ha.equals ha "b" {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} if (b.size() == 0) {
					System.out.println("B");
					break;
				} b.size() == 0 b.size() b.size b 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; ha = b.get(0) ha b.get(0) b.get b 0 b.remove(0) b.remove b 0 if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			} ha.equals("c") ha.equals ha "c" {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			} if (c.size() == 0) {
					System.out.println("C");
					break;
				} c.size() == 0 c.size() c.size c 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; ha = c.get(0) ha c.get(0) c.get c 0 c.remove(0) c.remove c 0 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	}

} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		String sa = scan.nextLine();
		String sb = scan.nextLine();
		String sc = scan.nextLine();

		int i = 0;
		int j = 0;
		int k = 0;

		List<String> a = new ArrayList<String>();
		List<String> b = new ArrayList<String>();
		List<String> c = new ArrayList<String>();

		for (i = 0; i < sa.length(); i++) {
			a.add(sa.charAt(i) + "");
		}

		for (j = 0; j < sb.length(); j++) {
			b.add(sb.charAt(j) + "");
		}

		for (k = 0; k < sc.length(); k++) {
			c.add(sc.charAt(k) + "");
		}

		String ha = "a";

		i = 1;

		for (;;) {

			if (ha.equals("a")) {

				if (a.size() == 0) {
					System.out.println("A");
					break;
				}

				ha = a.get(0);
				a.remove(0);

			} else if (ha.equals("b")) {

				if (b.size() == 0) {
					System.out.println("B");
					break;
				}

				ha = b.get(0);
				b.remove(0);

			} else if (ha.equals("c")) {

				if (c.size() == 0) {
					System.out.println("C");
					break;
				}

				ha = c.get(0);
				c.remove(0);

			}

		}

	}

}