import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	static String Sa, Sb, Sc;
	static StringBuilder a, b, c;
	static Map<Character, StringBuilder> map;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Sa = br.readLine();
		Sb = br.readLine();
		Sc = br.readLine();
		a = new StringBuilder(Sa);
		b = new StringBuilder(Sb);
		c = new StringBuilder(Sc);
		map = new HashMap<Character, StringBuilder>();
		map.put('a', a);
		map.put('b', b);
		map.put('c', c);
		char turn, next = 'a';
		while (true) {
			turn = next;
			if (map.get(turn).length() == 0) {
				System.out.println(Character.toUpperCase(turn));
				return;
			}
			next = map.get(turn).charAt(0);
			map.put(turn, map.get(turn).deleteCharAt(0));
		}
	}
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz