import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = new String[3];
		int[] idxes = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		}
		int idx = 0;
		while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		}
	}
} import java.util.*; util.* java public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = new String[3];
		int[] idxes = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		}
		int idx = 0;
		while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		}
	}
} Main public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = new String[3];
		int[] idxes = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		}
		int idx = 0;
		while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String[] arr = new String[3];
		int[] idxes = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		}
		int idx = 0;
		while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] arr = new String[3]; arr new String[3] 3 int[] idxes = new int[3]; idxes new int[3] 3 for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		} int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
			arr[i] = sc.next();
		} {
			arr[i] = sc.next();
		} arr[i] = sc.next() arr[i] arr i sc.next() sc.next sc int idx = 0; idx 0 while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		} true {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		} if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			} idxes[idx] >= arr[idx].length() idxes[idx] idxes idx arr[idx].length() arr[idx].length arr[idx] arr idx {
				System.out.println((char)('A' + idx));
				break;
			} System.out.println((char)('A' + idx)) System.out.println System.out System System.out (char)('A' + idx) 'A' idx break; int i = idxes[idx]; i idxes[idx] idxes idx idxes[idx]++ idxes[idx] idxes idx idx = arr[idx].charAt(i) - 'a' idx arr[idx].charAt(i) - 'a' arr[idx].charAt(i) arr[idx].charAt arr[idx] arr idx i 'a' String[] args args public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = new String[3];
		int[] idxes = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		}
		int idx = 0;
		while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		}
	}
} public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = new String[3];
		int[] idxes = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		}
		int idx = 0;
		while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		}
	}
} Main
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] arr = new String[3];
		int[] idxes = new int[3];
		for (int i = 0; i < 3; i++) {
			arr[i] = sc.next();
		}
		int idx = 0;
		while (true) {
			if (idxes[idx] >= arr[idx].length()) {
				System.out.println((char)('A' + idx));
				break;
			}
			int i = idxes[idx];
			idxes[idx]++;
			idx = arr[idx].charAt(i) - 'a';
		}
	}
}
