import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    } main {
        Scanner sc = new Scanner(System.in);
        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String Sa = sc.next(); Sa sc.next() sc.next sc String Sb = sc.next(); Sb sc.next() sc.next sc String Sc = sc.next(); Sc sc.next() sc.next sc char nextCard = 'a'; nextCard 'a' String winner = ""; winner "" while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        } winner.isEmpty() winner.isEmpty winner {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        } switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            } nextCard case 'a': 'a' case 'a': if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    } Sa.length() == 0 Sa.length() Sa.length Sa 0 {
                        winner = "A";
                        break;
                    } winner = "A" winner "A" break; nextCard = Sa.charAt(0) nextCard Sa.charAt(0) Sa.charAt Sa 0 Sa = Sa.substring(1, Sa.length()) Sa Sa.substring(1, Sa.length()) Sa.substring Sa 1 Sa.length() Sa.length Sa break; case 'b': 'b' case 'b': if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    } Sb.length() == 0 Sb.length() Sb.length Sb 0 {
                        winner = "B";
                        break;
                    } winner = "B" winner "B" break; nextCard = Sb.charAt(0) nextCard Sb.charAt(0) Sb.charAt Sb 0 Sb = Sb.substring(1, Sb.length()) Sb Sb.substring(1, Sb.length()) Sb.substring Sb 1 Sb.length() Sb.length Sb break; case 'c': 'c' case 'c': if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    } Sc.length() == 0 Sc.length() Sc.length Sc 0 {
                        winner = "C";
                        break;
                    } winner = "C" winner "C" break; nextCard = Sc.charAt(0) nextCard Sc.charAt(0) Sc.charAt Sc 0 Sc = Sc.substring(1, Sc.length()) Sc Sc.substring(1, Sc.length()) Sc.substring Sc 1 Sc.length() Sc.length Sc break; System.out.println(winner) System.out.println System.out System System.out winner String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String Sa = sc.next();
        String Sb = sc.next();
        String Sc = sc.next();

        char nextCard = 'a';
        String winner = "";

        while (winner.isEmpty()) {
            switch (nextCard) {
                case 'a':
                    if (Sa.length() == 0) {
                        winner = "A";
                        break;
                    }
                    nextCard = Sa.charAt(0);
                    Sa = Sa.substring(1, Sa.length());
                    break;
                case 'b':
                    if (Sb.length() == 0) {
                        winner = "B";
                        break;
                    }
                    nextCard = Sb.charAt(0);
                    Sb = Sb.substring(1, Sb.length());
                    break;
                case 'c':
                    if (Sc.length() == 0) {
                        winner = "C";
                        break;
                    }

                    nextCard = Sc.charAt(0);
                    Sc = Sc.substring(1, Sc.length());
                    break;

            }
        }
        System.out.println(winner);
    }
}
