import java.util.Scanner;

public class Main {
	int anum = 1;
	int bnum = 0;
	int cnum = 0;

	void run() {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	int anum = 1;
	int bnum = 0;
	int cnum = 0;

	void run() {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
} Main int anum = 1; anum 1 int bnum = 0; bnum 0 int cnum = 0; cnum 0 void run() {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	} run {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	} 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 char turn = a.charAt(0); turn a.charAt(0) a.charAt a 0 while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		} true {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		} if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			} turn == 'a' turn 'a' {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			} if(anum == a.length()) {
					System.out.println("A");
					break;
				} anum == a.length() anum a.length() a.length a {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; turn = a.charAt(anum) turn a.charAt(anum) a.charAt a anum anum++ anum if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			} turn == 'b' turn 'b' {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			} if(bnum == b.length()) {
					System.out.println("B");
					break;
				} bnum == b.length() bnum b.length() b.length b {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; turn = b.charAt(bnum) turn b.charAt(bnum) b.charAt b bnum bnum++ bnum {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			} if(cnum == c.length()) {
					System.out.println("C");
					break;
				} cnum == c.length() cnum c.length() c.length c {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; turn = c.charAt(cnum) turn c.charAt(cnum) c.charAt c cnum cnum++ cnum sc.close() sc.close sc public static void main(String[] args) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	int anum = 1;
	int bnum = 0;
	int cnum = 0;

	void run() {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	int anum = 1;
	int bnum = 0;
	int cnum = 0;

	void run() {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
} Main
import java.util.Scanner;

public class Main {
	int anum = 1;
	int bnum = 0;
	int cnum = 0;

	void run() {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char turn = a.charAt(0);
		while(true) {
			if(turn == 'a') {
				if(anum == a.length()) {
					System.out.println("A");
					break;
				}
				turn = a.charAt(anum);
				anum++;
			}else if (turn == 'b') {
				if(bnum == b.length()) {
					System.out.println("B");
					break;
				}
				turn = b.charAt(bnum);
				bnum++;
			}else {
				if(cnum == c.length()) {
					System.out.println("C");
					break;
				}
				turn = c.charAt(cnum);
				cnum++;
			}


		}
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}