import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] s = new String[3];

        for (int i = 0; i < 3; i++) {
            s[i] = scan.next();
        }

        int[] idx = new int[3];
        int nextTurn = 0;
        while (idx[nextTurn] < s[nextTurn].length()) {
            char nextCard = s[nextTurn].charAt(idx[nextTurn]);
            idx[nextTurn]++;
            nextTurn = nextCard - 'a';
        }

        char winner = 'A';
        winner += nextTurn;
        System.out.println(Character.toUpperCase(winner));
    }
} import java.util.*; util.* java import java.math.*; math.* java class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] s = new String[3];

        for (int i = 0; i < 3; i++) {
            s[i] = scan.next();
        }

        int[] idx = new int[3];
        int nextTurn = 0;
        while (idx[nextTurn] < s[nextTurn].length()) {
            char nextCard = s[nextTurn].charAt(idx[nextTurn]);
            idx[nextTurn]++;
            nextTurn = nextCard - 'a';
        }

        char winner = 'A';
        winner += nextTurn;
        System.out.println(Character.toUpperCase(winner));
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] s = new String[3];

        for (int i = 0; i < 3; i++) {
            s[i] = scan.next();
        }

        int[] idx = new int[3];
        int nextTurn = 0;
        while (idx[nextTurn] < s[nextTurn].length()) {
            char nextCard = s[nextTurn].charAt(idx[nextTurn]);
            idx[nextTurn]++;
            nextTurn = nextCard - 'a';
        }

        char winner = 'A';
        winner += nextTurn;
        System.out.println(Character.toUpperCase(winner));
    } main {
        Scanner scan = new Scanner(System.in);
        String[] s = new String[3];

        for (int i = 0; i < 3; i++) {
            s[i] = scan.next();
        }

        int[] idx = new int[3];
        int nextTurn = 0;
        while (idx[nextTurn] < s[nextTurn].length()) {
            char nextCard = s[nextTurn].charAt(idx[nextTurn]);
            idx[nextTurn]++;
            nextTurn = nextCard - 'a';
        }

        char winner = 'A';
        winner += nextTurn;
        System.out.println(Character.toUpperCase(winner));
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String[] s = new String[3]; s new String[3] 3 for (int i = 0; i < 3; i++) {
            s[i] = scan.next();
        } int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i {
            s[i] = scan.next();
        } {
            s[i] = scan.next();
        } s[i] = scan.next() s[i] s i scan.next() scan.next scan int[] idx = new int[3]; idx new int[3] 3 int nextTurn = 0; nextTurn 0 while (idx[nextTurn] < s[nextTurn].length()) {
            char nextCard = s[nextTurn].charAt(idx[nextTurn]);
            idx[nextTurn]++;
            nextTurn = nextCard - 'a';
        } idx[nextTurn] < s[nextTurn].length() idx[nextTurn] idx nextTurn s[nextTurn].length() s[nextTurn].length s[nextTurn] s nextTurn {
            char nextCard = s[nextTurn].charAt(idx[nextTurn]);
            idx[nextTurn]++;
            nextTurn = nextCard - 'a';
        } char nextCard = s[nextTurn].charAt(idx[nextTurn]); nextCard s[nextTurn].charAt(idx[nextTurn]) s[nextTurn].charAt s[nextTurn] s nextTurn idx[nextTurn] idx nextTurn idx[nextTurn]++ idx[nextTurn] idx nextTurn nextTurn = nextCard - 'a' nextTurn nextCard - 'a' nextCard 'a' char winner = 'A'; winner 'A' winner += nextTurn winner nextTurn System.out.println(Character.toUpperCase(winner)) System.out.println System.out System System.out Character.toUpperCase(winner) Character.toUpperCase Character winner String[] args args
import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] s = new String[3];

        for (int i = 0; i < 3; i++) {
            s[i] = scan.next();
        }

        int[] idx = new int[3];
        int nextTurn = 0;
        while (idx[nextTurn] < s[nextTurn].length()) {
            char nextCard = s[nextTurn].charAt(idx[nextTurn]);
            idx[nextTurn]++;
            nextTurn = nextCard - 'a';
        }

        char winner = 'A';
        winner += nextTurn;
        System.out.println(Character.toUpperCase(winner));
    }
}
