import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.List; List java.util import java.util.StringTokenizer; StringTokenizer java.util import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.io.InputStream; InputStream java.io public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) TaskB solver = new TaskB(); solver new TaskB() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        }

    } TaskB public void solve(int testNumber, InputReader in, PrintWriter out) {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        } solve {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        } List<Character> alice = new ArrayList<>(); alice new ArrayList<>() List<Character> bob = new ArrayList<>(); bob new ArrayList<>() List<Character> charlie = new ArrayList<>(); charlie new ArrayList<>() for (char x : in.next().toCharArray()) alice.add(x); char x in.next().toCharArray() in.next().toCharArray in.next() in.next in alice.add(x); alice.add(x) alice.add alice x for (char x : in.next().toCharArray()) bob.add(x); char x in.next().toCharArray() in.next().toCharArray in.next() in.next in bob.add(x); bob.add(x) bob.add bob x for (char x : in.next().toCharArray()) charlie.add(x); char x in.next().toCharArray() in.next().toCharArray in.next() in.next in charlie.add(x); charlie.add(x) charlie.add charlie x char next = alice.get(0); next alice.get(0) alice.get alice 0 boolean ans = true; ans true while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            } ans {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            } switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                } next case 'a': 'a' case 'a': if (alice.size() == 0) {
                            out.println("A");
                            return;
                        } alice.size() == 0 alice.size() alice.size alice 0 {
                            out.println("A");
                            return;
                        } out.println("A") out.println out "A" return; next = alice.get(0) next alice.get(0) alice.get alice 0 alice.remove(0) alice.remove alice 0 break; case 'b': 'b' case 'b': if (bob.size() == 0) {
                            out.println("B");
                            return;
                        } bob.size() == 0 bob.size() bob.size bob 0 {
                            out.println("B");
                            return;
                        } out.println("B") out.println out "B" return; next = bob.get(0) next bob.get(0) bob.get bob 0 bob.remove(0) bob.remove bob 0 break; case 'c': 'c' case 'c': if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        } charlie.size() == 0 charlie.size() charlie.size charlie 0 {
                            out.println("C");
                            return;
                        } out.println("C") out.println out "C" return; next = charlie.get(0) next charlie.get(0) charlie.get charlie 0 charlie.remove(0) charlie.remove charlie 0 break; int testNumber testNumber InputReader in in PrintWriter out out static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    } InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } InputReader {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } next {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            List<Character> alice = new ArrayList<>();
            List<Character> bob = new ArrayList<>();
            List<Character> charlie = new ArrayList<>();
            for (char x : in.next().toCharArray()) alice.add(x);
            for (char x : in.next().toCharArray()) bob.add(x);
            for (char x : in.next().toCharArray()) charlie.add(x);
            char next = alice.get(0);
            boolean ans = true;

            while (ans) {
                switch (next) {
                    case 'a':
                        if (alice.size() == 0) {
                            out.println("A");
                            return;
                        }
                        next = alice.get(0);
                        alice.remove(0);
                        break;
                    case 'b':
                        if (bob.size() == 0) {
                            out.println("B");
                            return;
                        }
                        next = bob.get(0);
                        bob.remove(0);
                        break;
                    case 'c':
                        if (charlie.size() == 0) {
                            out.println("C");
                            return;
                        }
                        next = charlie.get(0);
                        charlie.remove(0);
                        break;
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}

