import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		Map<String, Deque<String>> deq = new HashMap<>();
		String[] participants = new String[] {"a", "b", "c"};
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		}
		String prev = participants[0];
		while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		}
	}
} import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		Map<String, Deque<String>> deq = new HashMap<>();
		String[] participants = new String[] {"a", "b", "c"};
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		}
		String prev = participants[0];
		while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		}
	}
} Main private static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		Map<String, Deque<String>> deq = new HashMap<>();
		String[] participants = new String[] {"a", "b", "c"};
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		}
		String prev = participants[0];
		while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		}
	} main {
		Map<String, Deque<String>> deq = new HashMap<>();
		String[] participants = new String[] {"a", "b", "c"};
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		}
		String prev = participants[0];
		while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		}
	} Map<String, Deque<String>> deq = new HashMap<>(); deq new HashMap<>() String[] participants = new String[] {"a", "b", "c"}; participants new String[] {"a", "b", "c"} for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		} int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		} {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		} String s = sc.next(); s sc.next() sc.next sc deq.put(participants[i], new ArrayDeque<>()) deq.put deq participants[i] participants i new ArrayDeque<>() for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			} int j = 0; int j = 0; j 0 j < s.length() j s.length() s.length s j++ j++ j {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			} {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			} deq.get(participants[i]).addLast(s.charAt(j) + "") deq.get(participants[i]).addLast deq.get(participants[i]) deq.get deq participants[i] participants i s.charAt(j) + "" s.charAt(j) s.charAt s j "" String prev = participants[0]; prev participants[0] participants 0 while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		} true {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		} if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			} deq.get(prev).size() == 0 deq.get(prev).size() deq.get(prev).size deq.get(prev) deq.get deq prev 0 {
				System.out.println(prev.toUpperCase());
				return;
			} System.out.println(prev.toUpperCase()) System.out.println System.out System System.out prev.toUpperCase() prev.toUpperCase prev return; prev = deq.get(prev).pollFirst() prev deq.get(prev).pollFirst() deq.get(prev).pollFirst deq.get(prev) deq.get deq prev String[] args args public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		Map<String, Deque<String>> deq = new HashMap<>();
		String[] participants = new String[] {"a", "b", "c"};
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		}
		String prev = participants[0];
		while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		}
	}
} public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		Map<String, Deque<String>> deq = new HashMap<>();
		String[] participants = new String[] {"a", "b", "c"};
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		}
		String prev = participants[0];
		while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		}
	}
} Main
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		Map<String, Deque<String>> deq = new HashMap<>();
		String[] participants = new String[] {"a", "b", "c"};
		for (int i = 0; i < 3; i++) {
			String s = sc.next();
			deq.put(participants[i], new ArrayDeque<>());
			for (int j = 0; j < s.length(); j++) {
				deq.get(participants[i]).addLast(s.charAt(j) + "");
			}
		}
		String prev = participants[0];
		while (true) {
			if (deq.get(prev).size() == 0) {
				System.out.println(prev.toUpperCase());
				return;
			}
			prev = deq.get(prev).pollFirst();
		}
	}
}