import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();

        int currentPlayer = 0; // 0 = A, 1 = B, 2 = C
        while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();

        int currentPlayer = 0; // 0 = A, 1 = B, 2 = C
        while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();

        int currentPlayer = 0; // 0 = A, 1 = B, 2 = C
        while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();

        int currentPlayer = 0; // 0 = A, 1 = B, 2 = C
        while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String sa = scanner.next(); sa scanner.next() scanner.next scanner String sb = scanner.next(); sb scanner.next() scanner.next scanner String sc = scanner.next(); sc scanner.next() scanner.next scanner int currentPlayer = 0; currentPlayer 0 while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        } true {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        } char nextPlayer = 'a'; nextPlayer 'a' switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            } currentPlayer case 0: 0 case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                } if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    } sa.isEmpty() sa.isEmpty sa {
                        // A is win
                        System.out.print("A");
                        return;
                    } System.out.print("A") System.out.print System.out System System.out "A" return; nextPlayer = sa.charAt(0) nextPlayer sa.charAt(0) sa.charAt sa 0 sa = sa.substring(1) sa sa.substring(1) sa.substring sa 1 break; case 1: 1 case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                } if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    } sb.isEmpty() sb.isEmpty sb {
                        // A is win
                        System.out.print("B");
                        return;
                    } System.out.print("B") System.out.print System.out System System.out "B" return; nextPlayer = sb.charAt(0) nextPlayer sb.charAt(0) sb.charAt sb 0 sb = sb.substring(1) sb sb.substring(1) sb.substring sb 1 break; case 2: 2 case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                } if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    } sc.isEmpty() sc.isEmpty sc {
                        // A is win
                        System.out.print("C");
                        return;
                    } System.out.print("C") System.out.print System.out System System.out "C" return; nextPlayer = sc.charAt(0) nextPlayer sc.charAt(0) sc.charAt sc 0 sc = sc.substring(1) sc sc.substring(1) sc.substring sc 1 break; if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            } nextPlayer == 'a' nextPlayer 'a' {
                currentPlayer = 0;
            } currentPlayer = 0 currentPlayer 0 if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            } nextPlayer == 'b' nextPlayer 'b' {
                currentPlayer = 1;
            } currentPlayer = 1 currentPlayer 1 if (nextPlayer == 'c') {
                currentPlayer = 2;
            } nextPlayer == 'c' nextPlayer 'c' {
                currentPlayer = 2;
            } currentPlayer = 2 currentPlayer 2 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();

        int currentPlayer = 0; // 0 = A, 1 = B, 2 = C
        while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();

        int currentPlayer = 0; // 0 = A, 1 = B, 2 = C
        while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();

        int currentPlayer = 0; // 0 = A, 1 = B, 2 = C
        while (true) {
//            System.out.print("currentPlayer : " + currentPlayer);
//            System.out.print("sa : " + sa);
//            System.out.print("sb : " + sb);
//            System.out.print("sc : " + sc);

            char nextPlayer = 'a';
            switch (currentPlayer) {
                case 0: {
                    if (sa.isEmpty()) {
                        // A is win
                        System.out.print("A");
                        return;
                    }
                    nextPlayer = sa.charAt(0);
                    sa = sa.substring(1);
                    break;
                }
                case 1: {
                    if (sb.isEmpty()) {
                        // A is win
                        System.out.print("B");
                        return;
                    }
                    nextPlayer = sb.charAt(0);
                    sb = sb.substring(1);
                    break;
                }
                case 2: {
                    if (sc.isEmpty()) {
                        // A is win
                        System.out.print("C");
                        return;
                    }
                    nextPlayer = sc.charAt(0);
                    sc = sc.substring(1);
                    break;
                }
            }

            if (nextPlayer == 'a') {
                currentPlayer = 0;
            } else if (nextPlayer == 'b') {
                currentPlayer = 1;
            } else if (nextPlayer == 'c') {
                currentPlayer = 2;
            }
        }
    }
}
