import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();

        String currentA = aStr;
        String currentB = bStr;
        String currentC = cStr;
        String ans = "";
        boolean finish = false;

        // 初回の処理
        String next = String.valueOf(aStr.charAt(0));
        currentA = aStr.substring(1);
        while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        }

        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();

        String currentA = aStr;
        String currentB = bStr;
        String currentC = cStr;
        String ans = "";
        boolean finish = false;

        // 初回の処理
        String next = String.valueOf(aStr.charAt(0));
        currentA = aStr.substring(1);
        while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();

        String currentA = aStr;
        String currentB = bStr;
        String currentC = cStr;
        String ans = "";
        boolean finish = false;

        // 初回の処理
        String next = String.valueOf(aStr.charAt(0));
        currentA = aStr.substring(1);
        while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        }

        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();

        String currentA = aStr;
        String currentB = bStr;
        String currentC = cStr;
        String ans = "";
        boolean finish = false;

        // 初回の処理
        String next = String.valueOf(aStr.charAt(0));
        currentA = aStr.substring(1);
        while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        }

        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String aStr = sc.next(); aStr sc.next() sc.next sc String bStr = sc.next(); bStr sc.next() sc.next sc String cStr = sc.next(); cStr sc.next() sc.next sc String currentA = aStr; currentA aStr String currentB = bStr; currentB bStr String currentC = cStr; currentC cStr String ans = ""; ans "" boolean finish = false; finish false String next = String.valueOf(aStr.charAt(0)); next String.valueOf(aStr.charAt(0)) String.valueOf String aStr.charAt(0) aStr.charAt aStr 0 currentA = aStr.substring(1) currentA aStr.substring(1) aStr.substring aStr 1 while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        } !finish finish {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        } switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            } next case "a": "a" case "a": if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    } currentA.length() == 0 currentA.length() currentA.length currentA 0 {
                        ans = "A";
                        finish = true;
                        break;
                    } ans = "A" ans "A" finish = true finish true break; next = String.valueOf(currentA.charAt(0)) next String.valueOf(currentA.charAt(0)) String.valueOf String currentA.charAt(0) currentA.charAt currentA 0 currentA = currentA.substring(1) currentA currentA.substring(1) currentA.substring currentA 1 break; case "b": "b" case "b": if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    } currentB.length() == 0 currentB.length() currentB.length currentB 0 {
                        ans = "B";
                        finish = true;
                        break;
                    } ans = "B" ans "B" finish = true finish true break; next = String.valueOf(currentB.charAt(0)) next String.valueOf(currentB.charAt(0)) String.valueOf String currentB.charAt(0) currentB.charAt currentB 0 currentB = currentB.substring(1) currentB currentB.substring(1) currentB.substring currentB 1 break; case "c": "c" case "c": if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    } currentC.length() == 0 currentC.length() currentC.length currentC 0 {
                        ans = "C";
                        finish = true;
                        break;
                    } ans = "C" ans "C" finish = true finish true break; next = String.valueOf(currentC.charAt(0)) next String.valueOf(currentC.charAt(0)) String.valueOf String currentC.charAt(0) currentC.charAt currentC 0 currentC = currentC.substring(1) currentC currentC.substring(1) currentC.substring currentC 1 break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();

        String currentA = aStr;
        String currentB = bStr;
        String currentC = cStr;
        String ans = "";
        boolean finish = false;

        // 初回の処理
        String next = String.valueOf(aStr.charAt(0));
        currentA = aStr.substring(1);
        while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        }

        System.out.println(ans);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();

        String currentA = aStr;
        String currentB = bStr;
        String currentC = cStr;
        String ans = "";
        boolean finish = false;

        // 初回の処理
        String next = String.valueOf(aStr.charAt(0));
        currentA = aStr.substring(1);
        while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        }

        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String aStr = sc.next();
        String bStr = sc.next();
        String cStr = sc.next();

        String currentA = aStr;
        String currentB = bStr;
        String currentC = cStr;
        String ans = "";
        boolean finish = false;

        // 初回の処理
        String next = String.valueOf(aStr.charAt(0));
        currentA = aStr.substring(1);
        while (!finish) {

            switch (next) {
                case "a":
                    if (currentA.length() == 0) {
                        ans = "A";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentA.charAt(0));
                    currentA = currentA.substring(1);
                    break;
                case "b":
                    if (currentB.length() == 0) {
                        ans = "B";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentB.charAt(0));
                    currentB = currentB.substring(1);
                    break;
                case "c":
                    if (currentC.length() == 0) {
                        ans = "C";
                        finish = true;
                        break;
                    }
                    next = String.valueOf(currentC.charAt(0));
                    currentC = currentC.substring(1);
                    break;
            }

        }

        System.out.println(ans);
    }
}
