import java.util.Scanner;

public class Main {

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

		String person = a;
		String personNext = person.substring(0, 1);
		a = person.substring(1);

		while (playFlag) {

			if ("a".equals(personNext)) {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} else if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			}
		}
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

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

		String person = a;
		String personNext = person.substring(0, 1);
		a = person.substring(1);

		while (playFlag) {

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

		String person = a;
		String personNext = person.substring(0, 1);
		a = person.substring(1);

		while (playFlag) {

			if ("a".equals(personNext)) {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} else if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			}
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		boolean playFlag = true;
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String person = a;
		String personNext = person.substring(0, 1);
		a = person.substring(1);

		while (playFlag) {

			if ("a".equals(personNext)) {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} else if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			}
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) boolean playFlag = true; playFlag true 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 person = a; person a String personNext = person.substring(0, 1); personNext person.substring(0, 1) person.substring person 0 1 a = person.substring(1) a person.substring(1) person.substring person 1 while (playFlag) {

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

			if ("a".equals(personNext)) {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} else if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			}
		} if ("a".equals(personNext)) {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} else if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			} "a".equals(personNext) "a".equals "a" personNext {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} if (0 == a.length()) {
					System.out.println("A");
					break;
				} 0 == a.length() 0 a.length() a.length a {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; person = a person a personNext = a.substring(0, 1) personNext a.substring(0, 1) a.substring a 0 1 a = a.substring(1) a a.substring(1) a.substring a 1 if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			} "b".equals(personNext) "b".equals "b" personNext {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} if (0 == b.length()) {
					System.out.println("B");
					break;
				} 0 == b.length() 0 b.length() b.length b {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; personNext = b.substring(0, 1) personNext b.substring(0, 1) b.substring b 0 1 b = b.substring(1) b b.substring(1) b.substring b 1 person = b person b {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			} if (0 == c.length()) {
					System.out.println("C");
					break;
				} 0 == c.length() 0 c.length() c.length c {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; personNext = c.substring(0, 1) personNext c.substring(0, 1) c.substring c 0 1 c = c.substring(1) c c.substring(1) c.substring c 1 person = c person c sc.close() sc.close sc String args[] args public class Main {

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

		String person = a;
		String personNext = person.substring(0, 1);
		a = person.substring(1);

		while (playFlag) {

			if ("a".equals(personNext)) {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} else if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			}
		}
		sc.close();
	}
} public class Main {

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

		String person = a;
		String personNext = person.substring(0, 1);
		a = person.substring(1);

		while (playFlag) {

			if ("a".equals(personNext)) {
				if (0 == a.length()) {
					System.out.println("A");
					break;
				}
				person = a;
				personNext = a.substring(0, 1);
				a = a.substring(1);
			} else if ("b".equals(personNext)) {
				if (0 == b.length()) {
					System.out.println("B");
					break;
				}
				personNext = b.substring(0, 1);
				b = b.substring(1);
				person = b;
			} else {
				if (0 == c.length()) {
					System.out.println("C");
					break;
				}
				personNext = c.substring(0, 1);
				c = c.substring(1);
				person = c;
			}
		}
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

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

		String person = a;
		String personNext = person.substring(0, 1);
		a = person.substring(1);

		while (playFlag) {

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