import java.util.Scanner;

/**
 * B
 */
public class Main {

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

        String Sa = sc.nextLine();
        String Sb = sc.nextLine();
        String Sc = sc.nextLine();

        char ch = Sa.charAt(0);
        int a = 1;
        int b = 0;
        int c = 0;
        String ans = "";
        while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        }

        System.out.println(ans);
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {

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

        String Sa = sc.nextLine();
        String Sb = sc.nextLine();
        String Sc = sc.nextLine();

        char ch = Sa.charAt(0);
        int a = 1;
        int b = 0;
        int c = 0;
        String ans = "";
        while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        }

        System.out.println(ans);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String Sa = sc.nextLine();
        String Sb = sc.nextLine();
        String Sc = sc.nextLine();

        char ch = Sa.charAt(0);
        int a = 1;
        int b = 0;
        int c = 0;
        String ans = "";
        while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        }

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

        String Sa = sc.nextLine();
        String Sb = sc.nextLine();
        String Sc = sc.nextLine();

        char ch = Sa.charAt(0);
        int a = 1;
        int b = 0;
        int c = 0;
        String ans = "";
        while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        }

        System.out.println(ans);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String Sa = sc.nextLine(); Sa sc.nextLine() sc.nextLine sc String Sb = sc.nextLine(); Sb sc.nextLine() sc.nextLine sc String Sc = sc.nextLine(); Sc sc.nextLine() sc.nextLine sc char ch = Sa.charAt(0); ch Sa.charAt(0) Sa.charAt Sa 0 int a = 1; a 1 int b = 0; b 0 int c = 0; c 0 String ans = ""; ans "" while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        } true {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        } if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            } ch == 'a' ch 'a' {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } if (a == Sa.length()) {
                    ans = "A";
                    break;
                } a == Sa.length() a Sa.length() Sa.length Sa {
                    ans = "A";
                    break;
                } ans = "A" ans "A" break; ch = Sa.charAt(a) ch Sa.charAt(a) Sa.charAt Sa a a++ a if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            } ch == 'b' ch 'b' {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } if (b == Sb.length()) {
                    ans = "B";
                    break;
                } b == Sb.length() b Sb.length() Sb.length Sb {
                    ans = "B";
                    break;
                } ans = "B" ans "B" break; ch = Sb.charAt(b) ch Sb.charAt(b) Sb.charAt Sb b b++ b {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            } if (c == Sc.length()) {
                    ans = "C";
                    break;
                } c == Sc.length() c Sc.length() Sc.length Sc {
                    ans = "C";
                    break;
                } ans = "C" ans "C" break; ch = Sc.charAt(c) ch Sc.charAt(c) Sc.charAt Sc c c++ c System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {

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

        String Sa = sc.nextLine();
        String Sb = sc.nextLine();
        String Sc = sc.nextLine();

        char ch = Sa.charAt(0);
        int a = 1;
        int b = 0;
        int c = 0;
        String ans = "";
        while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        }

        System.out.println(ans);
        sc.close();
    }
} public class Main {

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

        String Sa = sc.nextLine();
        String Sb = sc.nextLine();
        String Sc = sc.nextLine();

        char ch = Sa.charAt(0);
        int a = 1;
        int b = 0;
        int c = 0;
        String ans = "";
        while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        }

        System.out.println(ans);
        sc.close();
    }
} Main
import java.util.Scanner;

/**
 * B
 */
public class Main {

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

        String Sa = sc.nextLine();
        String Sb = sc.nextLine();
        String Sc = sc.nextLine();

        char ch = Sa.charAt(0);
        int a = 1;
        int b = 0;
        int c = 0;
        String ans = "";
        while (true) {
            if (ch == 'a') {
                if (a == Sa.length()) {
                    ans = "A";
                    break;
                }
                ch = Sa.charAt(a);
                a++;
            } else if (ch == 'b') {
                if (b == Sb.length()) {
                    ans = "B";
                    break;
                }
                ch = Sb.charAt(b);
                b++;
            } else {
                if (c == Sc.length()) {
                    ans = "C";
                    break;
                }
                ch = Sc.charAt(c);
                c++;
            }
        }

        System.out.println(ans);
        sc.close();
    }
}