import java.util.Scanner;

class Main {
    static String a;
    static String b;
    static String c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        c = sc.next();
        char ac = a.charAt(0);
        int ans = 0;
        if (ac == 'a') {
            ans = DisCard(1);
        } else if (ac == 'b') {
            ans = DisCard(2);
        } else {
            ans = DisCard(3);
        }
        String answ = "";
        if (ans == 1) {
            answ = "A";
        } else if (ans == 2) {
            answ = "B";
        } else {
            answ = "C";
        }
        System.out.println(answ);
        sc.close();
    }

    public static int DisCard(int player) {
        if (player == 1) {
            if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else if (player == 2) {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        }
    }
} import java.util.Scanner; Scanner java.util class Main {
    static String a;
    static String b;
    static String c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        c = sc.next();
        char ac = a.charAt(0);
        int ans = 0;
        if (ac == 'a') {
            ans = DisCard(1);
        } else if (ac == 'b') {
            ans = DisCard(2);
        } else {
            ans = DisCard(3);
        }
        String answ = "";
        if (ans == 1) {
            answ = "A";
        } else if (ans == 2) {
            answ = "B";
        } else {
            answ = "C";
        }
        System.out.println(answ);
        sc.close();
    }

    public static int DisCard(int player) {
        if (player == 1) {
            if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else if (player == 2) {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        }
    }
} Main static String a; a static String b; b static String c; c public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        c = sc.next();
        char ac = a.charAt(0);
        int ans = 0;
        if (ac == 'a') {
            ans = DisCard(1);
        } else if (ac == 'b') {
            ans = DisCard(2);
        } else {
            ans = DisCard(3);
        }
        String answ = "";
        if (ans == 1) {
            answ = "A";
        } else if (ans == 2) {
            answ = "B";
        } else {
            answ = "C";
        }
        System.out.println(answ);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        c = sc.next();
        char ac = a.charAt(0);
        int ans = 0;
        if (ac == 'a') {
            ans = DisCard(1);
        } else if (ac == 'b') {
            ans = DisCard(2);
        } else {
            ans = DisCard(3);
        }
        String answ = "";
        if (ans == 1) {
            answ = "A";
        } else if (ans == 2) {
            answ = "B";
        } else {
            answ = "C";
        }
        System.out.println(answ);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) a = sc.next() a sc.next() sc.next sc b = sc.next() b sc.next() sc.next sc c = sc.next() c sc.next() sc.next sc char ac = a.charAt(0); ac a.charAt(0) a.charAt a 0 int ans = 0; ans 0 if (ac == 'a') {
            ans = DisCard(1);
        } else if (ac == 'b') {
            ans = DisCard(2);
        } else {
            ans = DisCard(3);
        } ac == 'a' ac 'a' {
            ans = DisCard(1);
        } ans = DisCard(1) ans DisCard(1) DisCard 1 if (ac == 'b') {
            ans = DisCard(2);
        } else {
            ans = DisCard(3);
        } ac == 'b' ac 'b' {
            ans = DisCard(2);
        } ans = DisCard(2) ans DisCard(2) DisCard 2 {
            ans = DisCard(3);
        } ans = DisCard(3) ans DisCard(3) DisCard 3 String answ = ""; answ "" if (ans == 1) {
            answ = "A";
        } else if (ans == 2) {
            answ = "B";
        } else {
            answ = "C";
        } ans == 1 ans 1 {
            answ = "A";
        } answ = "A" answ "A" if (ans == 2) {
            answ = "B";
        } else {
            answ = "C";
        } ans == 2 ans 2 {
            answ = "B";
        } answ = "B" answ "B" {
            answ = "C";
        } answ = "C" answ "C" System.out.println(answ) System.out.println System.out System System.out answ sc.close() sc.close sc String[] args args public static int DisCard(int player) {
        if (player == 1) {
            if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else if (player == 2) {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        }
    } DisCard {
        if (player == 1) {
            if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else if (player == 2) {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        }
    } if (player == 1) {
            if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else if (player == 2) {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } player == 1 player 1 {
            if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            } a.length() == 0 a.length() a.length a 0 {
                return 1;
            } return 1; 1 {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            } char c = a.charAt(0); c a.charAt(0) a.charAt a 0 a = a.substring(1) a a.substring(1) a.substring a 1 if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                } c == 'a' c 'a' {
                    return DisCard(1);
                } return DisCard(1); DisCard(1) DisCard 1 if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                } c == 'b' c 'b' {
                    return DisCard(2);
                } return DisCard(2); DisCard(2) DisCard 2 {
                    return DisCard(3);
                } return DisCard(3); DisCard(3) DisCard 3 if (player == 2) {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } player == 2 player 2 {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            } b.length() == 0 b.length() b.length b 0 {
                return 2;
            } return 2; 2 {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            } char c = b.charAt(0); c b.charAt(0) b.charAt b 0 b = b.substring(1) b b.substring(1) b.substring b 1 if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                } c == 'a' c 'a' {
                    return DisCard(1);
                } return DisCard(1); DisCard(1) DisCard 1 if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                } c == 'b' c 'b' {
                    return DisCard(2);
                } return DisCard(2); DisCard(2) DisCard 2 {
                    return DisCard(3);
                } return DisCard(3); DisCard(3) DisCard 3 {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            } c.length() == 0 c.length() c.length c 0 {
                return 3;
            } return 3; 3 {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            } char cha = c.charAt(0); cha c.charAt(0) c.charAt c 0 c = c.substring(1) c c.substring(1) c.substring c 1 if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                } cha == 'a' cha 'a' {
                    return DisCard(1);
                } return DisCard(1); DisCard(1) DisCard 1 if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                } cha == 'b' cha 'b' {
                    return DisCard(2);
                } return DisCard(2); DisCard(2) DisCard 2 {
                    return DisCard(3);
                } return DisCard(3); DisCard(3) DisCard 3 int player player
import java.util.Scanner;

class Main {
    static String a;
    static String b;
    static String c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        a = sc.next();
        b = sc.next();
        c = sc.next();
        char ac = a.charAt(0);
        int ans = 0;
        if (ac == 'a') {
            ans = DisCard(1);
        } else if (ac == 'b') {
            ans = DisCard(2);
        } else {
            ans = DisCard(3);
        }
        String answ = "";
        if (ans == 1) {
            answ = "A";
        } else if (ans == 2) {
            answ = "B";
        } else {
            answ = "C";
        }
        System.out.println(answ);
        sc.close();
    }

    public static int DisCard(int player) {
        if (player == 1) {
            if (a.length() == 0) {
                return 1;
            } else {
                char c = a.charAt(0);
                a = a.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else if (player == 2) {
            if (b.length() == 0) {
                return 2;
            } else {
                char c = b.charAt(0);
                b = b.substring(1);
                if (c == 'a') {
                    return DisCard(1);
                } else if (c == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        } else {
            if (c.length() == 0) {
                return 3;
            } else {
                char cha = c.charAt(0);
                c = c.substring(1);
                if (cha == 'a') {
                    return DisCard(1);
                } else if (cha == 'b') {
                    return DisCard(2);
                } else {
                    return DisCard(3);
                }
            }
        }
    }
}