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();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        }

    }
}
 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();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        }

    }
} 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();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        }

    } B public void solve(int testNumber, Scanner in, PrintWriter out) {
            String SA = in.next();
            String SB = in.next();
            String SC = in.next();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        } solve {
            String SA = in.next();
            String SB = in.next();
            String SC = in.next();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        } 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 int ia = 0 ia 0 ib = 0 ib 0 ic = 0; ic 0 int p = 0; p 0 while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            } true {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            } char win = 0; win 0 switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                } p case 0: 0 case 0: if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        } ia >= SA.length() ia SA.length() SA.length SA {
                            win = 'A';
                        } win = 'A' win 'A' {
                            p = SA.charAt(ia++) - 'a';
                        } p = SA.charAt(ia++) - 'a' p SA.charAt(ia++) - 'a' SA.charAt(ia++) SA.charAt SA ia++ ia 'a' break; case 1: 1 case 1: if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        } ib >= SB.length() ib SB.length() SB.length SB {
                            win = 'B';
                        } win = 'B' win 'B' {
                            p = SB.charAt(ib++) - 'a';
                        } p = SB.charAt(ib++) - 'a' p SB.charAt(ib++) - 'a' SB.charAt(ib++) SB.charAt SB ib++ ib 'a' break; default: default: if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        } ic >= SC.length() ic SC.length() SC.length SC {
                            win = 'C';
                        } win = 'C' win 'C' {
                            p = SC.charAt(ic++) - 'a';
                        } p = SC.charAt(ic++) - 'a' p SC.charAt(ic++) - 'a' SC.charAt(ic++) SC.charAt SC ic++ ic 'a' break; if (win != 0) {
                    out.println(win);
                    return;
                } win != 0 win 0 {
                    out.println(win);
                    return;
                } out.println(win) out.println out win return; 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();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        }

    }
} 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();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        }

    }
} 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();
            int ia = 0, ib = 0, ic = 0;
            int p = 0;
            while (true) {
                char win = 0;
                switch (p) {
                    case 0:
                        if (ia >= SA.length()) {
                            win = 'A';
                        } else {
                            p = SA.charAt(ia++) - 'a';
                        }
                        break;
                    case 1:
                        if (ib >= SB.length()) {
                            win = 'B';
                        } else {
                            p = SB.charAt(ib++) - 'a';
                        }
                        break;
                    default:
                        if (ic >= SC.length()) {
                            win = 'C';
                        } else {
                            p = SC.charAt(ic++) - 'a';
                        }
                        break;
                }
                if (win != 0) {
                    out.println(win);
                    return;
                }
            }
        }

    }
}

