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

public class Main {

	private static final char A = 'a';
	private static final char B = 'b';
	private static final char C = 'c';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	}

	/**
	 * @param now      現在プレーする人
	 * @param cardMap  カード情報のマップ
	 * @param indexMap 各自何枚目になったかのマップ
	 * @return ゲームの勝者（大文字）
	 */
	private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	}
} 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 final char A = 'a';
	private static final char B = 'b';
	private static final char C = 'c';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	}

	/**
	 * @param now      現在プレーする人
	 * @param cardMap  カード情報のマップ
	 * @param indexMap 各自何枚目になったかのマップ
	 * @return ゲームの勝者（大文字）
	 */
	private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	}
} Main private static final char A = 'a'; A 'a' private static final char B = 'b'; B 'b' private static final char C = 'c'; C 'c' public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	} main {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	} try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		} {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		} Scanner scanner = new Scanner(System.in) Scanner scanner = new Scanner(System.in) new Scanner(System.in) Map<Character, char[]> cardMap = new HashMap<>(); cardMap new HashMap<>() Map<Character, Integer> indexMap = new HashMap<>(); indexMap new HashMap<>() cardMap.put(A, scanner.next().toCharArray()) cardMap.put cardMap A scanner.next().toCharArray() scanner.next().toCharArray scanner.next() scanner.next scanner cardMap.put(B, scanner.next().toCharArray()) cardMap.put cardMap B scanner.next().toCharArray() scanner.next().toCharArray scanner.next() scanner.next scanner cardMap.put(C, scanner.next().toCharArray()) cardMap.put cardMap C scanner.next().toCharArray() scanner.next().toCharArray scanner.next() scanner.next scanner indexMap.put(A, 0) indexMap.put indexMap A 0 indexMap.put(B, 0) indexMap.put indexMap B 0 indexMap.put(C, 0) indexMap.put indexMap C 0 System.out.println(play(A, cardMap, indexMap)) System.out.println System.out System System.out play(A, cardMap, indexMap) play A cardMap indexMap String[] args args /**
	 * @param now      現在プレーする人
	 * @param cardMap  カード情報のマップ
	 * @param indexMap 各自何枚目になったかのマップ
	 * @return ゲームの勝者（大文字）
	 */
	private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	} play {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	} char[] cards = cardMap.get(now); cards cardMap.get(now) cardMap.get cardMap now int index = indexMap.get(now); index indexMap.get(now) indexMap.get indexMap now if (index >= cards.length) {
			return Character.toUpperCase(now);
		} index >= cards.length index cards.length cards cards.length {
			return Character.toUpperCase(now);
		} return Character.toUpperCase(now); Character.toUpperCase(now) Character.toUpperCase Character now char next = cards[index]; next cards[index] cards index indexMap.put(now, index + 1) indexMap.put indexMap now index + 1 index 1 return play(next, cardMap, indexMap); play(next, cardMap, indexMap) play next cardMap indexMap char now now Map<Character, char[]> cardMap cardMap Map<Character, Integer> indexMap indexMap public class Main {

	private static final char A = 'a';
	private static final char B = 'b';
	private static final char C = 'c';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	}

	/**
	 * @param now      現在プレーする人
	 * @param cardMap  カード情報のマップ
	 * @param indexMap 各自何枚目になったかのマップ
	 * @return ゲームの勝者（大文字）
	 */
	private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	}
} public class Main {

	private static final char A = 'a';
	private static final char B = 'b';
	private static final char C = 'c';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	}

	/**
	 * @param now      現在プレーする人
	 * @param cardMap  カード情報のマップ
	 * @param indexMap 各自何枚目になったかのマップ
	 * @return ゲームの勝者（大文字）
	 */
	private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	}
} Main
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	private static final char A = 'a';
	private static final char B = 'b';
	private static final char C = 'c';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Map<Character, char[]> cardMap = new HashMap<>();
			Map<Character, Integer> indexMap = new HashMap<>();
			cardMap.put(A, scanner.next().toCharArray());
			cardMap.put(B, scanner.next().toCharArray());
			cardMap.put(C, scanner.next().toCharArray());
			indexMap.put(A, 0);
			indexMap.put(B, 0);
			indexMap.put(C, 0);
			System.out.println(play(A, cardMap, indexMap));
		}
	}

	/**
	 * @param now      現在プレーする人
	 * @param cardMap  カード情報のマップ
	 * @param indexMap 各自何枚目になったかのマップ
	 * @return ゲームの勝者（大文字）
	 */
	private static char play(char now, Map<Character, char[]> cardMap, Map<Character, Integer> indexMap) {
		char[] cards = cardMap.get(now);
		int index = indexMap.get(now);
		if (index >= cards.length) {
			return Character.toUpperCase(now);
		}
		char next = cards[index];
		indexMap.put(now, index + 1);
		return play(next, cardMap, indexMap);
	}
}
