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

public class Main {
    public static void main(String[] args) throws IOException {

        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

        String cardsOfA = input.readLine();
        String cardsOfB = input.readLine();
        String cardsOfC = input.readLine();

        int lengthOfCardsOfA = cardsOfA.length();
        int lengthOfCardsOfB = cardsOfB.length();
        int lengthOfCardsOfC = cardsOfC.length();

        int currentCardPositionOfA = 0;
        int currentCardPositionOfB = 0;
        int currentCardPositionOfC = 0;

        boolean isWinnerDetermined = false;
        char nameOfWinner = ' ';
        char currentPlayer = 'a';
        while (!isWinnerDetermined) {
            if (currentPlayer == 'a') {
                if (doesPlayerFinish(currentCardPositionOfA, lengthOfCardsOfA)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'A';
                } else {
                    currentPlayer = cardsOfA.charAt(currentCardPositionOfA);
                    currentCardPositionOfA += 1;
                }
            } else if (currentPlayer == 'b') {
                if (doesPlayerFinish(currentCardPositionOfB, lengthOfCardsOfB)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'B';
                } else {
                    currentPlayer = cardsOfB.charAt(currentCardPositionOfB);
                    currentCardPositionOfB += 1;
                }

            } else if (currentPlayer == 'c') {
                if (doesPlayerFinish(currentCardPositionOfC, lengthOfCardsOfC)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'C';
                } else {
                    currentPlayer = cardsOfC.charAt(currentCardPositionOfC);
                    currentCardPositionOfC += 1;
                }
            }
        }



        System.out.println(nameOfWinner);


    }

    private static boolean doesPlayerFinish(int currentCardPositionOfThePlayer, int lengthOfCardsOfThePlayer) {
        return currentCardPositionOfThePlayer >= lengthOfCardsOfThePlayer;
    }

}
/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