import java.util.Scanner;

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

		String tmp = in.nextLine();
		char[][] input = new char[3][];
		input[0] = tmp.toCharArray();
		tmp = in.nextLine();
		input[1] = tmp.toCharArray();
		tmp = in.nextLine();
		input[2] = tmp.toCharArray();

		String ans = "";
		int id = 0;
		int[] n = new int[3];
		while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		}

		// 出力
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String tmp = in.nextLine();
		char[][] input = new char[3][];
		input[0] = tmp.toCharArray();
		tmp = in.nextLine();
		input[1] = tmp.toCharArray();
		tmp = in.nextLine();
		input[2] = tmp.toCharArray();

		String ans = "";
		int id = 0;
		int[] n = new int[3];
		while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		}

		// 出力
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String tmp = in.nextLine();
		char[][] input = new char[3][];
		input[0] = tmp.toCharArray();
		tmp = in.nextLine();
		input[1] = tmp.toCharArray();
		tmp = in.nextLine();
		input[2] = tmp.toCharArray();

		String ans = "";
		int id = 0;
		int[] n = new int[3];
		while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		}

		// 出力
		System.out.println(ans);
	} main {
		Scanner in = new Scanner(System.in);

		String tmp = in.nextLine();
		char[][] input = new char[3][];
		input[0] = tmp.toCharArray();
		tmp = in.nextLine();
		input[1] = tmp.toCharArray();
		tmp = in.nextLine();
		input[2] = tmp.toCharArray();

		String ans = "";
		int id = 0;
		int[] n = new int[3];
		while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		}

		// 出力
		System.out.println(ans);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) String tmp = in.nextLine(); tmp in.nextLine() in.nextLine in char[][] input = new char[3][]; input new char[3][] 3 input[0] = tmp.toCharArray() input[0] input 0 tmp.toCharArray() tmp.toCharArray tmp tmp = in.nextLine() tmp in.nextLine() in.nextLine in input[1] = tmp.toCharArray() input[1] input 1 tmp.toCharArray() tmp.toCharArray tmp tmp = in.nextLine() tmp in.nextLine() in.nextLine in input[2] = tmp.toCharArray() input[2] input 2 tmp.toCharArray() tmp.toCharArray tmp String ans = ""; ans "" int id = 0; id 0 int[] n = new int[3]; n new int[3] 3 while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		} true {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		} n[id] = n[id] + 1 n[id] n id n[id] + 1 n[id] n id 1 if (n[0] > input[0].length) {
				ans = "A";
				break;

			} n[0] > input[0].length n[0] n 0 input[0].length input[0] input 0 input[0].length {
				ans = "A";
				break;

			} ans = "A" ans "A" break; if (n[1] > input[1].length) {
				ans = "B";
				break;

			} n[1] > input[1].length n[1] n 1 input[1].length input[1] input 1 input[1].length {
				ans = "B";
				break;

			} ans = "B" ans "B" break; if (n[2] > input[2].length) {
				ans = "C";
				break;
			} n[2] > input[2].length n[2] n 2 input[2].length input[2] input 2 input[2].length {
				ans = "C";
				break;
			} ans = "C" ans "C" break; char next = input[id][n[id]-1]; next input[id][n[id]-1] input[id] input id n[id]-1 n[id] n id 1 if (next == 'a') {
				id = 0;
			} next == 'a' next 'a' {
				id = 0;
			} id = 0 id 0 if (next == 'b') {
				id = 1;
			} next == 'b' next 'b' {
				id = 1;
			} id = 1 id 1 if (next == 'c') {
				id = 2;
			} next == 'c' next 'c' {
				id = 2;
			} id = 2 id 2 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String tmp = in.nextLine();
		char[][] input = new char[3][];
		input[0] = tmp.toCharArray();
		tmp = in.nextLine();
		input[1] = tmp.toCharArray();
		tmp = in.nextLine();
		input[2] = tmp.toCharArray();

		String ans = "";
		int id = 0;
		int[] n = new int[3];
		while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		}

		// 出力
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String tmp = in.nextLine();
		char[][] input = new char[3][];
		input[0] = tmp.toCharArray();
		tmp = in.nextLine();
		input[1] = tmp.toCharArray();
		tmp = in.nextLine();
		input[2] = tmp.toCharArray();

		String ans = "";
		int id = 0;
		int[] n = new int[3];
		while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		}

		// 出力
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

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

		String tmp = in.nextLine();
		char[][] input = new char[3][];
		input[0] = tmp.toCharArray();
		tmp = in.nextLine();
		input[1] = tmp.toCharArray();
		tmp = in.nextLine();
		input[2] = tmp.toCharArray();

		String ans = "";
		int id = 0;
		int[] n = new int[3];
		while (true) {
			n[id] = n[id] + 1;
			if (n[0] > input[0].length) {
				ans = "A";
				break;

			}
			if (n[1] > input[1].length) {
				ans = "B";
				break;

			}
			if (n[2] > input[2].length) {
				ans = "C";
				break;
			}

			char next = input[id][n[id]-1];
			if (next == 'a') {
				id = 0;
			}
			if (next == 'b') {
				id = 1;
			}
			if (next == 'c') {
				id = 2;
			}
		}

		// 出力
		System.out.println(ans);
	}
}