import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String lineA = scanner.next();
		String lineB = scanner.next();
		String lineC = scanner.next();

		String next = lineA.substring(0,1);
		lineA = lineA.substring(1);
		while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		}

		scanner.close();
	}

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

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String lineA = scanner.next();
		String lineB = scanner.next();
		String lineC = scanner.next();

		String next = lineA.substring(0,1);
		lineA = lineA.substring(1);
		while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		}

		scanner.close();
	}

} Main public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String lineA = scanner.next();
		String lineB = scanner.next();
		String lineC = scanner.next();

		String next = lineA.substring(0,1);
		lineA = lineA.substring(1);
		while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		}

		scanner.close();
	} main {
		Scanner scanner =new Scanner(System.in);
		String lineA = scanner.next();
		String lineB = scanner.next();
		String lineC = scanner.next();

		String next = lineA.substring(0,1);
		lineA = lineA.substring(1);
		while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		}

		scanner.close();
	} Scanner scanner =new Scanner(System.in); scanner new Scanner(System.in) String lineA = scanner.next(); lineA scanner.next() scanner.next scanner String lineB = scanner.next(); lineB scanner.next() scanner.next scanner String lineC = scanner.next(); lineC scanner.next() scanner.next scanner String next = lineA.substring(0,1); next lineA.substring(0,1) lineA.substring lineA 0 1 lineA = lineA.substring(1) lineA lineA.substring(1) lineA.substring lineA 1 while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		} true {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		} if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			} next.equals("a") next.equals next "a" {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			} if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				} lineA.length() == 0 lineA.length() lineA.length lineA 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; {
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				} next = lineA.substring(0,1) next lineA.substring(0,1) lineA.substring lineA 0 1 lineA = lineA.substring(1) lineA lineA.substring(1) lineA.substring lineA 1 if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			} next.equals("b") next.equals next "b" {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			} if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				} lineB.length() == 0 lineB.length() lineB.length lineB 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; {
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				} next = lineB.substring(0,1) next lineB.substring(0,1) lineB.substring lineB 0 1 lineB = lineB.substring(1) lineB lineB.substring(1) lineB.substring lineB 1 if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			} next.equals("c") next.equals next "c" {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			} if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				} lineC.length() == 0 lineC.length() lineC.length lineC 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; {
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				} next = lineC.substring(0,1) next lineC.substring(0,1) lineC.substring lineC 0 1 lineC = lineC.substring(1) lineC lineC.substring(1) lineC.substring lineC 1 scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String lineA = scanner.next();
		String lineB = scanner.next();
		String lineC = scanner.next();

		String next = lineA.substring(0,1);
		lineA = lineA.substring(1);
		while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		}

		scanner.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String lineA = scanner.next();
		String lineB = scanner.next();
		String lineC = scanner.next();

		String next = lineA.substring(0,1);
		lineA = lineA.substring(1);
		while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		}

		scanner.close();
	}

} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String lineA = scanner.next();
		String lineB = scanner.next();
		String lineC = scanner.next();

		String next = lineA.substring(0,1);
		lineA = lineA.substring(1);
		while (true) {
			if (next.equals("a")) {
				if (lineA.length() == 0) {
					System.out.println("A");
					break;
				}else{
					next = lineA.substring(0,1);
					lineA = lineA.substring(1);
				}
			}else if (next.equals("b")) {
				if (lineB.length() == 0) {
					System.out.println("B");
					break;
				}else{
					next = lineB.substring(0,1);
					lineB = lineB.substring(1);
				}
			}else if (next.equals("c")) {
				if (lineC.length() == 0) {
					System.out.println("C");
					break;
				}else{
					next = lineC.substring(0,1);
					lineC = lineC.substring(1);
				}
			}
		}

		scanner.close();
	}

}
