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));
		}
	}
} import java.io.*; io.* java import java.util.*; util.* java import java.math.*; math.* java 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));
		}
	}
} Main static String Sa Sa Sb Sb Sc; Sc static StringBuilder a a b b c; c static Map<Character, StringBuilder> map; 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));
		}
	} main {
		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));
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Sa = br.readLine() Sa br.readLine() br.readLine br Sb = br.readLine() Sb br.readLine() br.readLine br Sc = br.readLine() Sc br.readLine() br.readLine br a = new StringBuilder(Sa) a new StringBuilder(Sa) b = new StringBuilder(Sb) b new StringBuilder(Sb) c = new StringBuilder(Sc) c new StringBuilder(Sc) map = new HashMap<Character, StringBuilder>() map new HashMap<Character, StringBuilder>() map.put('a', a) map.put map 'a' a map.put('b', b) map.put map 'b' b map.put('c', c) map.put map 'c' c char turn turn next = 'a'; 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));
		} 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));
		} turn = next turn next if (map.get(turn).length() == 0) {
				System.out.println(Character.toUpperCase(turn));
				return;
			} map.get(turn).length() == 0 map.get(turn).length() map.get(turn).length map.get(turn) map.get map turn 0 {
				System.out.println(Character.toUpperCase(turn));
				return;
			} System.out.println(Character.toUpperCase(turn)) System.out.println System.out System System.out Character.toUpperCase(turn) Character.toUpperCase Character turn return; next = map.get(turn).charAt(0) next map.get(turn).charAt(0) map.get(turn).charAt map.get(turn) map.get map turn 0 map.put(turn, map.get(turn).deleteCharAt(0)) map.put map turn map.get(turn).deleteCharAt(0) map.get(turn).deleteCharAt map.get(turn) map.get map turn 0 String[] args args 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));
		}
	}
} 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));
		}
	}
} Main
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));
		}
	}
}
