import java.util.*;
import java.util.function.ToDoubleFunction;


public class Main {
    private static final String ex = "abcb\n" +
            "aacb\n" +
            "bccc";

    public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    }

    private static void solve(Scanner scanner) {
        LinkedList<Character> A = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) A.add(c);
        LinkedList<Character> B = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) B.add(c);
        LinkedList<Character> C = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) C.add(c);

        LinkedList<Character> player = A;

        while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        }
    }
} import java.util.*; util.* java import java.util.function.ToDoubleFunction; ToDoubleFunction java.util.function public class Main {
    private static final String ex = "abcb\n" +
            "aacb\n" +
            "bccc";

    public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    }

    private static void solve(Scanner scanner) {
        LinkedList<Character> A = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) A.add(c);
        LinkedList<Character> B = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) B.add(c);
        LinkedList<Character> C = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) C.add(c);

        LinkedList<Character> player = A;

        while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        }
    }
} Main private static final String ex = "abcb\n" +
            "aacb\n" +
            "bccc"; ex "abcb\n" +
            "aacb\n" +
            "bccc" "abcb\n" +
            "aacb\n" +
            "bccc" "abcb\n" "aacb\n" "bccc" public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    } main {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    } solve(new Scanner(System.in)) solve new Scanner(System.in) String[] args args private static void solve(Scanner scanner) {
        LinkedList<Character> A = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) A.add(c);
        LinkedList<Character> B = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) B.add(c);
        LinkedList<Character> C = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) C.add(c);

        LinkedList<Character> player = A;

        while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        }
    } solve {
        LinkedList<Character> A = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) A.add(c);
        LinkedList<Character> B = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) B.add(c);
        LinkedList<Character> C = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) C.add(c);

        LinkedList<Character> player = A;

        while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        }
    } LinkedList<Character> A = new LinkedList(); A new LinkedList() for (char c: scanner.nextLine().toCharArray()) A.add(c); char c scanner.nextLine().toCharArray() scanner.nextLine().toCharArray scanner.nextLine() scanner.nextLine scanner A.add(c); A.add(c) A.add A c LinkedList<Character> B = new LinkedList(); B new LinkedList() for (char c: scanner.nextLine().toCharArray()) B.add(c); char c scanner.nextLine().toCharArray() scanner.nextLine().toCharArray scanner.nextLine() scanner.nextLine scanner B.add(c); B.add(c) B.add B c LinkedList<Character> C = new LinkedList(); C new LinkedList() for (char c: scanner.nextLine().toCharArray()) C.add(c); char c scanner.nextLine().toCharArray() scanner.nextLine().toCharArray scanner.nextLine() scanner.nextLine scanner C.add(c); C.add(c) C.add C c LinkedList<Character> player = A; player A while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        } true {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        } Character top = player.poll(); top player.poll() player.poll player if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C; top == 'a' top 'a' player = A player A if (top == 'b') player = B;
            else if (top == 'c') player = C; top == 'b' top 'b' player = B player B if (top == 'c') player = C; top == 'c' top 'c' player = C player C if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            } player.size() == 0 player.size() player.size player 0 {
                System.out.println(Character.toUpperCase(top));
                break;
            } System.out.println(Character.toUpperCase(top)) System.out.println System.out System System.out Character.toUpperCase(top) Character.toUpperCase Character top break; Scanner scanner scanner public class Main {
    private static final String ex = "abcb\n" +
            "aacb\n" +
            "bccc";

    public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    }

    private static void solve(Scanner scanner) {
        LinkedList<Character> A = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) A.add(c);
        LinkedList<Character> B = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) B.add(c);
        LinkedList<Character> C = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) C.add(c);

        LinkedList<Character> player = A;

        while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        }
    }
} public class Main {
    private static final String ex = "abcb\n" +
            "aacb\n" +
            "bccc";

    public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    }

    private static void solve(Scanner scanner) {
        LinkedList<Character> A = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) A.add(c);
        LinkedList<Character> B = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) B.add(c);
        LinkedList<Character> C = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) C.add(c);

        LinkedList<Character> player = A;

        while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        }
    }
} Main
import java.util.*;
import java.util.function.ToDoubleFunction;


public class Main {
    private static final String ex = "abcb\n" +
            "aacb\n" +
            "bccc";

    public static void main(String[] args) {
        solve(new Scanner(System.in));
//        solve(new Scanner(ex));
    }

    private static void solve(Scanner scanner) {
        LinkedList<Character> A = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) A.add(c);
        LinkedList<Character> B = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) B.add(c);
        LinkedList<Character> C = new LinkedList();
        for (char c: scanner.nextLine().toCharArray()) C.add(c);

        LinkedList<Character> player = A;

        while (true) {
            Character top = player.poll();
            if (top == 'a') player = A;
            else if (top == 'b') player = B;
            else if (top == 'c') player = C;

            if (player.size() == 0) {
                System.out.println(Character.toUpperCase(top));
                break;
            }
        }
    }
}
