import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    }

    static char solve(String[] S) {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    }

    static char solve(String[] S) {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] S = new String[3]; S new String[3] 3 for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        } int i = 0; int i = 0; i 0 i < S.length i S.length S S.length ++i ++i i {
            S[i] = sc.next();
        } {
            S[i] = sc.next();
        } S[i] = sc.next() S[i] S i sc.next() sc.next sc System.out.println(solve(S)) System.out.println System.out System System.out solve(S) solve S sc.close() sc.close sc String[] args args static char solve(String[] S) {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    } solve {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    } int indices[] = new int[S.length]; indices new int[S.length] S.length S S.length int turn = 0; turn 0 while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        } indices[turn] != S[turn].length() indices[turn] indices turn S[turn].length() S[turn].length S[turn] S turn {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        } int nextTurn = S[turn].charAt(indices[turn]) - 'a'; nextTurn S[turn].charAt(indices[turn]) - 'a' S[turn].charAt(indices[turn]) S[turn].charAt S[turn] S turn indices[turn] indices turn 'a' ++indices[turn] indices[turn] indices turn turn = nextTurn turn nextTurn return (char) (turn + 'A'); (char) (turn + 'A') turn 'A' String[] S S public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    }

    static char solve(String[] S) {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    }

    static char solve(String[] S) {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] S = new String[3];
        for (int i = 0; i < S.length; ++i) {
            S[i] = sc.next();
        }

        System.out.println(solve(S));

        sc.close();
    }

    static char solve(String[] S) {
        int indices[] = new int[S.length];
        int turn = 0;
        while (indices[turn] != S[turn].length()) {
            int nextTurn = S[turn].charAt(indices[turn]) - 'a';
            ++indices[turn];

            turn = nextTurn;
        }

        return (char) (turn + 'A');
    }
}