import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	} main {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[][] s = new char[3][]; s new char[3][] 3 for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		} int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
			s[i] = sc.next().toCharArray();
		} {
			s[i] = sc.next().toCharArray();
		} s[i] = sc.next().toCharArray() s[i] s i sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc sc.close() sc.close sc int now = 0; now 0 int[] idx = new int[3]; idx new int[3] 3 while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		} true {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		} if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			} idx[now] == s[now].length idx[now] idx now s[now].length s[now] s now s[now].length {
				System.out.println((char) ('A' + now));
				return;
			} System.out.println((char) ('A' + now)) System.out.println System.out System System.out (char) ('A' + now) 'A' now return; char next = s[now][idx[now]]; next s[now][idx[now]] s[now] s now idx[now] idx now idx[now]++ idx[now] idx now now = next - 'a' now next - 'a' next 'a' String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[][] s = new char[3][];
		for (int i = 0; i < 3; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int now = 0;
		int[] idx = new int[3];
		while (true) {
			if (idx[now] == s[now].length) {
				System.out.println((char) ('A' + now));
				return;
			}
			char next = s[now][idx[now]];
			idx[now]++;
			now = next - 'a';
		}
	}
}
