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 next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	}
} 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 next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	}
} 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 next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	} 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 next =a.substring(0, 1); next a.substring(0, 1) a.substring a 0 1 a = a.substring(1, a.length()) a a.substring(1, a.length()) a.substring a 1 a.length() a.length a for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		} ; {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		} {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		} if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			} next.equals("a") next.equals next "a" {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			} if (a.isEmpty()) {
					System.out.println("A");
					return;
				} a.isEmpty() a.isEmpty a {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; next = a.substring(0, 1) next a.substring(0, 1) a.substring a 0 1 a = a.substring(1, a.length()) a a.substring(1, a.length()) a.substring a 1 a.length() a.length a if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			} next.equals("b") next.equals next "b" {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} if(b.isEmpty()) {
					System.out.println("B");
					return;
				} b.isEmpty() b.isEmpty b {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; next = b.substring(0, 1) next b.substring(0, 1) b.substring b 0 1 b = b.substring(1, b.length()) b b.substring(1, b.length()) b.substring b 1 b.length() b.length b {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			} if(c.isEmpty()) {
					System.out.println("C");
					return;
				} c.isEmpty() c.isEmpty c {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; next = c.substring(0, 1) next c.substring(0, 1) c.substring c 0 1 c = c.substring(1, c.length()) c c.substring(1, c.length()) c.substring c 1 c.length() c.length 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 next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	}
} 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 next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	}
} 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 next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	}
}
