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

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io 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;
    }

} 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);


    } main {

        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);


    } BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); input new BufferedReader(new InputStreamReader(System.in)) String cardsOfA = input.readLine(); cardsOfA input.readLine() input.readLine input String cardsOfB = input.readLine(); cardsOfB input.readLine() input.readLine input String cardsOfC = input.readLine(); cardsOfC input.readLine() input.readLine input int lengthOfCardsOfA = cardsOfA.length(); lengthOfCardsOfA cardsOfA.length() cardsOfA.length cardsOfA int lengthOfCardsOfB = cardsOfB.length(); lengthOfCardsOfB cardsOfB.length() cardsOfB.length cardsOfB int lengthOfCardsOfC = cardsOfC.length(); lengthOfCardsOfC cardsOfC.length() cardsOfC.length cardsOfC int currentCardPositionOfA = 0; currentCardPositionOfA 0 int currentCardPositionOfB = 0; currentCardPositionOfB 0 int currentCardPositionOfC = 0; currentCardPositionOfC 0 boolean isWinnerDetermined = false; isWinnerDetermined false char nameOfWinner = ' '; nameOfWinner ' ' char currentPlayer = 'a'; 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;
                }
            }
        } !isWinnerDetermined 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;
                }
            }
        } 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;
                }
            } currentPlayer == 'a' currentPlayer 'a' {
                if (doesPlayerFinish(currentCardPositionOfA, lengthOfCardsOfA)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'A';
                } else {
                    currentPlayer = cardsOfA.charAt(currentCardPositionOfA);
                    currentCardPositionOfA += 1;
                }
            } if (doesPlayerFinish(currentCardPositionOfA, lengthOfCardsOfA)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'A';
                } else {
                    currentPlayer = cardsOfA.charAt(currentCardPositionOfA);
                    currentCardPositionOfA += 1;
                } doesPlayerFinish(currentCardPositionOfA, lengthOfCardsOfA) doesPlayerFinish currentCardPositionOfA lengthOfCardsOfA {
                    isWinnerDetermined = true;
                    nameOfWinner = 'A';
                } isWinnerDetermined = true isWinnerDetermined true nameOfWinner = 'A' nameOfWinner 'A' {
                    currentPlayer = cardsOfA.charAt(currentCardPositionOfA);
                    currentCardPositionOfA += 1;
                } currentPlayer = cardsOfA.charAt(currentCardPositionOfA) currentPlayer cardsOfA.charAt(currentCardPositionOfA) cardsOfA.charAt cardsOfA currentCardPositionOfA currentCardPositionOfA += 1 currentCardPositionOfA 1 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;
                }
            } currentPlayer == 'b' currentPlayer 'b' {
                if (doesPlayerFinish(currentCardPositionOfB, lengthOfCardsOfB)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'B';
                } else {
                    currentPlayer = cardsOfB.charAt(currentCardPositionOfB);
                    currentCardPositionOfB += 1;
                }

            } if (doesPlayerFinish(currentCardPositionOfB, lengthOfCardsOfB)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'B';
                } else {
                    currentPlayer = cardsOfB.charAt(currentCardPositionOfB);
                    currentCardPositionOfB += 1;
                } doesPlayerFinish(currentCardPositionOfB, lengthOfCardsOfB) doesPlayerFinish currentCardPositionOfB lengthOfCardsOfB {
                    isWinnerDetermined = true;
                    nameOfWinner = 'B';
                } isWinnerDetermined = true isWinnerDetermined true nameOfWinner = 'B' nameOfWinner 'B' {
                    currentPlayer = cardsOfB.charAt(currentCardPositionOfB);
                    currentCardPositionOfB += 1;
                } currentPlayer = cardsOfB.charAt(currentCardPositionOfB) currentPlayer cardsOfB.charAt(currentCardPositionOfB) cardsOfB.charAt cardsOfB currentCardPositionOfB currentCardPositionOfB += 1 currentCardPositionOfB 1 if (currentPlayer == 'c') {
                if (doesPlayerFinish(currentCardPositionOfC, lengthOfCardsOfC)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'C';
                } else {
                    currentPlayer = cardsOfC.charAt(currentCardPositionOfC);
                    currentCardPositionOfC += 1;
                }
            } currentPlayer == 'c' currentPlayer 'c' {
                if (doesPlayerFinish(currentCardPositionOfC, lengthOfCardsOfC)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'C';
                } else {
                    currentPlayer = cardsOfC.charAt(currentCardPositionOfC);
                    currentCardPositionOfC += 1;
                }
            } if (doesPlayerFinish(currentCardPositionOfC, lengthOfCardsOfC)) {
                    isWinnerDetermined = true;
                    nameOfWinner = 'C';
                } else {
                    currentPlayer = cardsOfC.charAt(currentCardPositionOfC);
                    currentCardPositionOfC += 1;
                } doesPlayerFinish(currentCardPositionOfC, lengthOfCardsOfC) doesPlayerFinish currentCardPositionOfC lengthOfCardsOfC {
                    isWinnerDetermined = true;
                    nameOfWinner = 'C';
                } isWinnerDetermined = true isWinnerDetermined true nameOfWinner = 'C' nameOfWinner 'C' {
                    currentPlayer = cardsOfC.charAt(currentCardPositionOfC);
                    currentCardPositionOfC += 1;
                } currentPlayer = cardsOfC.charAt(currentCardPositionOfC) currentPlayer cardsOfC.charAt(currentCardPositionOfC) cardsOfC.charAt cardsOfC currentCardPositionOfC currentCardPositionOfC += 1 currentCardPositionOfC 1 System.out.println(nameOfWinner) System.out.println System.out System System.out nameOfWinner String[] args args private static boolean doesPlayerFinish(int currentCardPositionOfThePlayer, int lengthOfCardsOfThePlayer) {
        return currentCardPositionOfThePlayer >= lengthOfCardsOfThePlayer;
    } doesPlayerFinish {
        return currentCardPositionOfThePlayer >= lengthOfCardsOfThePlayer;
    } return currentCardPositionOfThePlayer >= lengthOfCardsOfThePlayer; currentCardPositionOfThePlayer >= lengthOfCardsOfThePlayer currentCardPositionOfThePlayer lengthOfCardsOfThePlayer int currentCardPositionOfThePlayer currentCardPositionOfThePlayer int lengthOfCardsOfThePlayer lengthOfCardsOfThePlayer 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;
    }

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

} Main
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;
    }

}