import java.util.*;

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

        char turn = 'a';

        while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.nextLine();
        String b = scan.nextLine();
        String c = scan.nextLine();

        char turn = 'a';

        while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.nextLine();
        String b = scan.nextLine();
        String c = scan.nextLine();

        char turn = 'a';

        while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        }
    } main {
        Scanner scan = new Scanner(System.in);
        String a = scan.nextLine();
        String b = scan.nextLine();
        String c = scan.nextLine();

        char turn = 'a';

        while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String a = scan.nextLine(); a scan.nextLine() scan.nextLine scan String b = scan.nextLine(); b scan.nextLine() scan.nextLine scan String c = scan.nextLine(); c scan.nextLine() scan.nextLine scan char turn = 'a'; turn 'a' while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        } true {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        } if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            } turn == 'a' turn 'a' {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                } a.length() == 0 a.length() a.length a 0 {
                    System.out.println('A');
                    System.exit(0);
                } System.out.println('A') System.out.println System.out System System.out 'A' System.exit(0) System.exit System 0 turn = a.charAt(0) turn a.charAt(0) a.charAt a 0 a = a.substring(1) a a.substring(1) a.substring a 1 if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            } turn == 'b' turn 'b' {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                } b.length() == 0 b.length() b.length b 0 {
                    System.out.println('B');
                    System.exit(0);
                } System.out.println('B') System.out.println System.out System System.out 'B' System.exit(0) System.exit System 0 turn = b.charAt(0) turn b.charAt(0) b.charAt b 0 b = b.substring(1) b b.substring(1) b.substring b 1 {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            } if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                } c.length() == 0 c.length() c.length c 0 {
                    System.out.println('C');
                    System.exit(0);
                } System.out.println('C') System.out.println System.out System System.out 'C' System.exit(0) System.exit System 0 turn = c.charAt(0) turn c.charAt(0) c.charAt c 0 c = c.substring(1) c c.substring(1) c.substring c 1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.nextLine();
        String b = scan.nextLine();
        String c = scan.nextLine();

        char turn = 'a';

        while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

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

        char turn = 'a';

        while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        }
    }
} Main
import java.util.*;

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

        char turn = 'a';

        while (true) {
            if (turn == 'a') {

                if (a.length() == 0) {
                    System.out.println('A');
                    System.exit(0);
                }
                turn = a.charAt(0);
                a = a.substring(1);

            } else if (turn == 'b') {

                if (b.length() == 0) {
                    System.out.println('B');
                    System.exit(0);
                }
                turn = b.charAt(0);
                b = b.substring(1);

            } else {

                if (c.length() == 0) {
                    System.out.println('C');
                    System.exit(0);
                }
                turn = c.charAt(0);
                c = c.substring(1);

            }
        }
    }
}
