import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        }

    }
}
 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.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        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 Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) B solver = new B(); solver new B() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        }

    } B public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        } solve {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        } String Sa = in.next(); Sa in.next() in.next in String Sb = in.next(); Sb in.next() in.next in String Sc = in.next(); Sc in.next() in.next in String ans = "A"; ans "A" String next = "a"; next "a" StringBuilder current = new StringBuilder(); current new StringBuilder() current.append(Sa) current.append current Sa while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            } true {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            } if (current.length() == 0) break; current.length() == 0 current.length() current.length current 0 break; if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                } "a".equals(next) "a".equals "a" next {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } Sa = current.substring(1) Sa current.substring(1) current.substring current 1 next = current.substring(0, 1) next current.substring(0, 1) current.substring current 0 1 if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                } "b".equals(next) "b".equals "b" next {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } Sb = current.substring(1) Sb current.substring(1) current.substring current 1 next = current.substring(0, 1) next current.substring(0, 1) current.substring current 0 1 if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                } "c".equals(next) "c".equals "c" next {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                } Sc = current.substring(1) Sc current.substring(1) current.substring current 1 next = current.substring(0, 1) next current.substring(0, 1) current.substring current 0 1 current.delete(0, current.length()) current.delete current 0 current.length() current.length current if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                } "a".equals(next) "a".equals "a" next {
                    ans = "A";
                    current.append(Sa);
                } ans = "A" ans "A" current.append(Sa) current.append current Sa if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                } "b".equals(next) "b".equals "b" next {
                    ans = "B";
                    current.append(Sb);
                } ans = "B" ans "B" current.append(Sb) current.append current Sb if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                } "c".equals(next) "c".equals "c" next {
                    ans = "C";
                    current.append(Sc);
                } ans = "C" ans "C" current.append(Sc) current.append current Sc out.println(ans) out.println out ans int testNumber testNumber Scanner in in PrintWriter out out public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        }

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String Sa = in.next();
            String Sb = in.next();
            String Sc = in.next();
            String ans = "A";
            String next = "a";

            StringBuilder current = new StringBuilder();
            current.append(Sa);
            while (true) {
                if (current.length() == 0) break;
                if ("a".equals(next)) {
                    Sa = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("b".equals(next)) {
                    Sb = current.substring(1);
                    next = current.substring(0, 1);
                } else if ("c".equals(next)) {
                    Sc = current.substring(1);
                    next = current.substring(0, 1);
                }
                current.delete(0, current.length());
                if ("a".equals(next)) {
                    ans = "A";
                    current.append(Sa);
                }
                if ("b".equals(next)) {
                    ans = "B";
                    current.append(Sb);
                }
                if ("c".equals(next)) {
                    ans = "C";
                    current.append(Sc);
                }
            }

            out.println(ans);
        }

    }
}

