import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    }

} Main public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    } main {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) String[] sa = s.next().split(""); sa s.next().split("") s.next().split s.next() s.next s "" String[] sb = s.next().split(""); sb s.next().split("") s.next().split s.next() s.next s "" String[] sc = s.next().split(""); sc s.next().split("") s.next().split s.next() s.next s "" int idxA = 0; idxA 0 int idxB = 0; idxB 0 int idxC = 0; idxC 0 String turn = "a"; turn "a" while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        } true {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        } if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            } "a".equals(turn) "a".equals "a" turn {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                } idxA == sa.length idxA sa.length sa sa.length {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; turn = sa[idxA] turn sa[idxA] sa idxA idxA++ idxA if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            } "b".equals(turn) "b".equals "b" turn {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                } idxB == sb.length idxB sb.length sb sb.length {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; turn = sb[idxB] turn sb[idxB] sb idxB idxB++ idxB if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            } "c".equals(turn) "c".equals "c" turn {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            } if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                } idxC == sc.length idxC sc.length sc sc.length {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; turn = sc[idxC] turn sc[idxC] sc idxC idxC++ idxC String[] args args public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    }

} public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    }

}
