import java.util.Scanner;

/**
 * Created by wild on 16/09/26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String one = scan.next();
        String two = scan.next();
        String three = scan.next();

        boolean ok = true;
        char turn = 'a';
        char winner = 'a';

        while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        }
        System.out.println(winner);
    }

    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String one = scan.next();
        String two = scan.next();
        String three = scan.next();

        boolean ok = true;
        char turn = 'a';
        char winner = 'a';

        while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        }
        System.out.println(winner);
    }

    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String one = scan.next();
        String two = scan.next();
        String three = scan.next();

        boolean ok = true;
        char turn = 'a';
        char winner = 'a';

        while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        }
        System.out.println(winner);
    } main {
        Scanner scan = new Scanner(System.in);
        String one = scan.next();
        String two = scan.next();
        String three = scan.next();

        boolean ok = true;
        char turn = 'a';
        char winner = 'a';

        while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        }
        System.out.println(winner);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String one = scan.next(); one scan.next() scan.next scan String two = scan.next(); two scan.next() scan.next scan String three = scan.next(); three scan.next() scan.next scan boolean ok = true; ok true char turn = 'a'; turn 'a' char winner = 'a'; winner 'a' while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        } ok {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        } switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            } turn case 'a': 'a' case 'a': if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    } one.equals(" ") one.equals one " " {
                        winner = 'A';
                        ok = false;
                    } winner = 'A' winner 'A' ok = false ok false {
                        turn = one.charAt(0);
                        one = ret(one);
                    } turn = one.charAt(0) turn one.charAt(0) one.charAt one 0 one = ret(one) one ret(one) ret one break; case 'b': 'b' case 'b': if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    } two.equals(" ") two.equals two " " {
                        winner = 'B';
                        ok = false;
                    } winner = 'B' winner 'B' ok = false ok false {
                        turn = two.charAt(0);
                        two = ret(two);
                    } turn = two.charAt(0) turn two.charAt(0) two.charAt two 0 two = ret(two) two ret(two) ret two break; case 'c': 'c' case 'c': if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    } three.equals(" ") three.equals three " " {
                        winner = 'C';
                        ok = false;
                    } winner = 'C' winner 'C' ok = false ok false {
                        turn = three.charAt(0);
                        three = ret(three);
                    } turn = three.charAt(0) turn three.charAt(0) three.charAt three 0 three = ret(three) three ret(three) ret three break; System.out.println(winner) System.out.println System.out System System.out winner String[] args args public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    } ret {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    } if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        } str.length() != 1 str.length() str.length str 1 {
            return str.substring(1);
        } return str.substring(1); str.substring(1) str.substring str 1 {
            return " ";
        } return " "; " " String str str public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String one = scan.next();
        String two = scan.next();
        String three = scan.next();

        boolean ok = true;
        char turn = 'a';
        char winner = 'a';

        while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        }
        System.out.println(winner);
    }

    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String one = scan.next();
        String two = scan.next();
        String three = scan.next();

        boolean ok = true;
        char turn = 'a';
        char winner = 'a';

        while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        }
        System.out.println(winner);
    }

    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
} Main
import java.util.Scanner;

/**
 * Created by wild on 16/09/26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String one = scan.next();
        String two = scan.next();
        String three = scan.next();

        boolean ok = true;
        char turn = 'a';
        char winner = 'a';

        while (ok) {
            switch (turn) {
                case 'a':
                    if (one.equals(" ")){
                        winner = 'A';
                        ok = false;
                    }else {
                        turn = one.charAt(0);
                        one = ret(one);
                    }
                    break;
                case 'b':
                    if (two.equals(" ")){
                        winner = 'B';
                        ok = false;
                    }else {
                        turn = two.charAt(0);
                        two = ret(two);
                    }
                    break;
                case 'c':
                    if (three.equals(" ")){
                        winner = 'C';
                        ok = false;
                    }else {
                        turn = three.charAt(0);
                        three = ret(three);
                    }
                    break;
            }

        }
        System.out.println(winner);
    }

    public static String ret(String str) {
        if (str.length() != 1) {
            return str.substring(1);
        } else {
            return " ";
        }
    }
}