import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String stra = sc.nextLine();
        String strb = sc.nextLine();
        String strc = sc.nextLine();

        int cntA = 0;
        int cntB = 0;
        int cntC = 0;
        int nextIda = 0;
        int nextIdb = 0;
        int nextIdc = 0;
        char next = 'a';
        char ans = 'x';

        outline: while (true) {
            switch (next) {
            case 'a':
                cntA++;
                if (cntA > stra.length()) {
                    ans = 'a';
                    break outline;
                }
                next = stra.charAt(nextIda);
                nextIda++;
                break;
            case 'b':
                cntB++;
                if (cntB > strb.length()) {
                    ans = 'b';
                    break outline;
                }
                next = strb.charAt(nextIdb);
                nextIdb++;
                break;
            case 'c':
                cntC++;
                if (cntC > strc.length()) {
                    ans = 'c';
                    break outline;
                }
                next = strc.charAt(nextIdc);
                nextIdc++;
                break;
            }
        }

        if (ans == 'a') {
            System.out.println('A');
        } else if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        }
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String stra = sc.nextLine();
        String strb = sc.nextLine();
        String strc = sc.nextLine();

        int cntA = 0;
        int cntB = 0;
        int cntC = 0;
        int nextIda = 0;
        int nextIdb = 0;
        int nextIdc = 0;
        char next = 'a';
        char ans = 'x';

        outline: while (true) {
            switch (next) {
            case 'a':
                cntA++;
                if (cntA > stra.length()) {
                    ans = 'a';
                    break outline;
                }
                next = stra.charAt(nextIda);
                nextIda++;
                break;
            case 'b':
                cntB++;
                if (cntB > strb.length()) {
                    ans = 'b';
                    break outline;
                }
                next = strb.charAt(nextIdb);
                nextIdb++;
                break;
            case 'c':
                cntC++;
                if (cntC > strc.length()) {
                    ans = 'c';
                    break outline;
                }
                next = strc.charAt(nextIdc);
                nextIdc++;
                break;
            }
        }

        if (ans == 'a') {
            System.out.println('A');
        } else if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String stra = sc.nextLine();
        String strb = sc.nextLine();
        String strc = sc.nextLine();

        int cntA = 0;
        int cntB = 0;
        int cntC = 0;
        int nextIda = 0;
        int nextIdb = 0;
        int nextIdc = 0;
        char next = 'a';
        char ans = 'x';

        outline: while (true) {
            switch (next) {
            case 'a':
                cntA++;
                if (cntA > stra.length()) {
                    ans = 'a';
                    break outline;
                }
                next = stra.charAt(nextIda);
                nextIda++;
                break;
            case 'b':
                cntB++;
                if (cntB > strb.length()) {
                    ans = 'b';
                    break outline;
                }
                next = strb.charAt(nextIdb);
                nextIdb++;
                break;
            case 'c':
                cntC++;
                if (cntC > strc.length()) {
                    ans = 'c';
                    break outline;
                }
                next = strc.charAt(nextIdc);
                nextIdc++;
                break;
            }
        }

        if (ans == 'a') {
            System.out.println('A');
        } else if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String stra = sc.nextLine();
        String strb = sc.nextLine();
        String strc = sc.nextLine();

        int cntA = 0;
        int cntB = 0;
        int cntC = 0;
        int nextIda = 0;
        int nextIdb = 0;
        int nextIdc = 0;
        char next = 'a';
        char ans = 'x';

        outline: while (true) {
            switch (next) {
            case 'a':
                cntA++;
                if (cntA > stra.length()) {
                    ans = 'a';
                    break outline;
                }
                next = stra.charAt(nextIda);
                nextIda++;
                break;
            case 'b':
                cntB++;
                if (cntB > strb.length()) {
                    ans = 'b';
                    break outline;
                }
                next = strb.charAt(nextIdb);
                nextIdb++;
                break;
            case 'c':
                cntC++;
                if (cntC > strc.length()) {
                    ans = 'c';
                    break outline;
                }
                next = strc.charAt(nextIdc);
                nextIdc++;
                break;
            }
        }

        if (ans == 'a') {
            System.out.println('A');
        } else if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String stra = sc.nextLine(); stra sc.nextLine() sc.nextLine sc String strb = sc.nextLine(); strb sc.nextLine() sc.nextLine sc String strc = sc.nextLine(); strc sc.nextLine() sc.nextLine sc int cntA = 0; cntA 0 int cntB = 0; cntB 0 int cntC = 0; cntC 0 int nextIda = 0; nextIda 0 int nextIdb = 0; nextIdb 0 int nextIdc = 0; nextIdc 0 char next = 'a'; next 'a' char ans = 'x'; ans 'x' if (ans == 'a') {
            System.out.println('A');
        } else if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        } ans == 'a' ans 'a' {
            System.out.println('A');
        } System.out.println('A') System.out.println System.out System System.out 'A' if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        } ans == 'b' ans 'b' {
            System.out.println('B');
        } System.out.println('B') System.out.println System.out System System.out 'B' {
            System.out.println('C');
        } System.out.println('C') System.out.println System.out System System.out 'C' String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String stra = sc.nextLine();
        String strb = sc.nextLine();
        String strc = sc.nextLine();

        int cntA = 0;
        int cntB = 0;
        int cntC = 0;
        int nextIda = 0;
        int nextIdb = 0;
        int nextIdc = 0;
        char next = 'a';
        char ans = 'x';

        outline: while (true) {
            switch (next) {
            case 'a':
                cntA++;
                if (cntA > stra.length()) {
                    ans = 'a';
                    break outline;
                }
                next = stra.charAt(nextIda);
                nextIda++;
                break;
            case 'b':
                cntB++;
                if (cntB > strb.length()) {
                    ans = 'b';
                    break outline;
                }
                next = strb.charAt(nextIdb);
                nextIdb++;
                break;
            case 'c':
                cntC++;
                if (cntC > strc.length()) {
                    ans = 'c';
                    break outline;
                }
                next = strc.charAt(nextIdc);
                nextIdc++;
                break;
            }
        }

        if (ans == 'a') {
            System.out.println('A');
        } else if (ans == 'b') {
            System.out.println('B');
        } else {
            System.out.println('C');
        }
    }
}