import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    }
} Main public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    } main {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    } try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        } {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        } Scanner in = new Scanner(System.in) Scanner in = new Scanner(System.in) new Scanner(System.in) String a = in.next(); a in.next() in.next in String b = in.next(); b in.next() in.next in String c = in.next(); c in.next() in.next in String[] Sabc = new String[] { a, b, c, }; Sabc new String[] { a, b, c, } int[] index = new int[3]; index new int[3] 3 int current = 0; current 0 for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            } ; {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            } {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            } if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                } index[current] >= Sabc[current].length() index[current] index current Sabc[current].length() Sabc[current].length Sabc[current] Sabc current {
                    System.out.println((char) ('A' + current));
                    return;
                } System.out.println((char) ('A' + current)) System.out.println System.out System System.out (char) ('A' + current) 'A' current return; current = Sabc[current].charAt(index[current]++) - 'a' current Sabc[current].charAt(index[current]++) - 'a' Sabc[current].charAt(index[current]++) Sabc[current].charAt Sabc[current] Sabc current index[current]++ index[current] index current 'a' String[] args args public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String a = in.next();
            String b = in.next();
            String c = in.next();

            String[] Sabc = new String[] { a, b, c, };
            int[] index = new int[3];
            int current = 0;
            for (;;) {
                if (index[current] >= Sabc[current].length()) {
                    System.out.println((char) ('A' + current));
                    return;
                }
                current = Sabc[current].charAt(index[current]++) - 'a';
            }
        }
    }
}
