import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static String[] cards = new String[3];
	static int[] idxes = new int[3];
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		}
		int cur = 0;
		while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		}
		String player = "ABC";
		System.out.println(player.charAt(cur));
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	static String[] cards = new String[3];
	static int[] idxes = new int[3];
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		}
		int cur = 0;
		while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		}
		String player = "ABC";
		System.out.println(player.charAt(cur));
	}

} Main static String[] cards = new String[3]; cards new String[3] 3 static int[] idxes = new int[3]; idxes new int[3] 3 public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		}
		int cur = 0;
		while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		}
		String player = "ABC";
		System.out.println(player.charAt(cur));
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		}
		int cur = 0;
		while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		}
		String player = "ABC";
		System.out.println(player.charAt(cur));
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		} int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
			String line = br.readLine();
			cards[i] = line;
		} {
			String line = br.readLine();
			cards[i] = line;
		} String line = br.readLine(); line br.readLine() br.readLine br cards[i] = line cards[i] cards i line int cur = 0; cur 0 while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		} true {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		} if (idxes[cur] >= cards[cur].length()) {
				break;
			} idxes[cur] >= cards[cur].length() idxes[cur] idxes cur cards[cur].length() cards[cur].length cards[cur] cards cur {
				break;
			} break; char next = cards[cur].charAt(idxes[cur]); next cards[cur].charAt(idxes[cur]) cards[cur].charAt cards[cur] cards cur idxes[cur] idxes cur idxes[cur]++ idxes[cur] idxes cur cur = next - 'a' cur next - 'a' next 'a' String player = "ABC"; player "ABC" System.out.println(player.charAt(cur)) System.out.println System.out System System.out player.charAt(cur) player.charAt player cur String[] args args public class Main {

	static String[] cards = new String[3];
	static int[] idxes = new int[3];
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		}
		int cur = 0;
		while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		}
		String player = "ABC";
		System.out.println(player.charAt(cur));
	}

} public class Main {

	static String[] cards = new String[3];
	static int[] idxes = new int[3];
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		}
		int cur = 0;
		while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		}
		String player = "ABC";
		System.out.println(player.charAt(cur));
	}

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static String[] cards = new String[3];
	static int[] idxes = new int[3];
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		for (int i=0; i<3; i++) {
			String line = br.readLine();
			cards[i] = line;
		}
		int cur = 0;
		while (true) {
			if (idxes[cur] >= cards[cur].length()) {
				break;
			}
			char next = cards[cur].charAt(idxes[cur]);
			idxes[cur]++;
			cur = next - 'a';
		}
		String player = "ABC";
		System.out.println(player.charAt(cur));
	}

}
