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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
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);
        B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit();
        solver.solve(1, in, out);
        out.close();
    }

    static class B3CardGameForThreeABCEdit {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        }

    }

    static class InputReader implements AutoCloseable {
        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 void close() {
        }

    }
}
 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.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.List; List java.util import java.util.StringTokenizer; StringTokenizer java.util import java.io.BufferedReader; BufferedReader java.io import java.util.LinkedList; LinkedList 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);
        B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit();
        solver.solve(1, in, out);
        out.close();
    }

    static class B3CardGameForThreeABCEdit {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        }

    }

    static class InputReader implements AutoCloseable {
        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 void close() {
        }

    }
} 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);
        B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit();
        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);
        B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit();
        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) B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit(); solver new B3CardGameForThreeABCEdit() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class B3CardGameForThreeABCEdit {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        }

    } B3CardGameForThreeABCEdit public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        } solve {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        } 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 List<Character> listA = new LinkedList<>(); listA new LinkedList<>() List<Character> listB = new LinkedList<>(); listB new LinkedList<>() List<Character> listC = new LinkedList<>(); listC new LinkedList<>() for (char ch : a.toCharArray()) {
                listA.add(ch);
            } char ch a.toCharArray() a.toCharArray a {
                listA.add(ch);
            } {
                listA.add(ch);
            } listA.add(ch) listA.add listA ch for (char ch : b.toCharArray()) {
                listB.add(ch);
            } char ch b.toCharArray() b.toCharArray b {
                listB.add(ch);
            } {
                listB.add(ch);
            } listB.add(ch) listB.add listB ch for (char ch : c.toCharArray()) {
                listC.add(ch);
            } char ch c.toCharArray() c.toCharArray c {
                listC.add(ch);
            } {
                listC.add(ch);
            } listC.add(ch) listC.add listC ch char s = (listA.isEmpty()) ? 'a' : listA.remove(0); s (listA.isEmpty()) ? 'a' : listA.remove(0) (listA.isEmpty()) listA.isEmpty listA 'a' listA.remove(0) listA.remove listA 0 while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            } true {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            } switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                } s case 'a': 'a' case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    } if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        } listA.isEmpty() listA.isEmpty listA {
                            out.println("A");
                            return;
                        } out.println("A") out.println out "A" return; s = listA.remove(0) s listA.remove(0) listA.remove listA 0 break; case 'b': 'b' case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    } if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        } listB.isEmpty() listB.isEmpty listB {
                            out.println("B");
                            return;
                        } out.println("B") out.println out "B" return; s = listB.remove(0) s listB.remove(0) listB.remove listB 0 break; case 'c': 'c' case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    } if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        } listC.isEmpty() listC.isEmpty listC {
                            out.println("C");
                            return;
                        } out.println("C") out.println out "C" return; s = listC.remove(0) s listC.remove(0) listC.remove listC 0 break; int testNumber testNumber InputReader in in PrintWriter out out static class InputReader implements AutoCloseable {
        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 void close() {
        }

    } 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 void close() {
        } close {
        } AutoCloseable 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);
        B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit();
        solver.solve(1, in, out);
        out.close();
    }

    static class B3CardGameForThreeABCEdit {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        }

    }

    static class InputReader implements AutoCloseable {
        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 void close() {
        }

    }
} 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);
        B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit();
        solver.solve(1, in, out);
        out.close();
    }

    static class B3CardGameForThreeABCEdit {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        }

    }

    static class InputReader implements AutoCloseable {
        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 void close() {
        }

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
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);
        B3CardGameForThreeABCEdit solver = new B3CardGameForThreeABCEdit();
        solver.solve(1, in, out);
        out.close();
    }

    static class B3CardGameForThreeABCEdit {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.next();
            String b = in.next();
            String c = in.next();
            List<Character> listA = new LinkedList<>();
            List<Character> listB = new LinkedList<>();
            List<Character> listC = new LinkedList<>();
            for (char ch : a.toCharArray()) {
                listA.add(ch);
            }
            for (char ch : b.toCharArray()) {
                listB.add(ch);
            }
            for (char ch : c.toCharArray()) {
                listC.add(ch);
            }
            char s = (listA.isEmpty()) ? 'a' : listA.remove(0);
            while (true) {
                switch (s) {
                    case 'a': {
                        if (listA.isEmpty()) {
                            out.println("A");
                            return;
                        }
                        s = listA.remove(0);
                        break;
                    }
                    case 'b': {
                        if (listB.isEmpty()) {
                            out.println("B");
                            return;
                        }
                        s = listB.remove(0);
                        break;
                    }
                    case 'c': {
                        if (listC.isEmpty()) {
                            out.println("C");
                            return;
                        }
                        s = listC.remove(0);
                        break;
                    }
                }

            }
        }

    }

    static class InputReader implements AutoCloseable {
        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 void close() {
        }

    }
}

