
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    } main {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String SA = sc.next(); SA sc.next() sc.next sc String SB = sc.next(); SB sc.next() sc.next sc String SC = sc.next(); SC sc.next() sc.next sc int iA = 0; iA 0 int iB = 0; iB 0 int iC = 0; iC 0 char player = 'a'; player 'a' while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        } player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length() player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length() player == 'a' && iA < SA.length() player == 'a' player 'a' iA < SA.length() iA SA.length() SA.length SA player == 'b' && iB < SB.length() player == 'b' player 'b' iB < SB.length() iB SB.length() SB.length SB player == 'c' && iC < SC.length() player == 'c' player 'c' iC < SC.length() iC SC.length() SC.length SC {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        } switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            } player case 'a': 'a' case 'a': player = SA.charAt(iA) player SA.charAt(iA) SA.charAt SA iA iA += 1 iA 1 break; case 'b': 'b' case 'b': player = SB.charAt(iB) player SB.charAt(iB) SB.charAt SB iB iB += 1 iB 1 break; case 'c': 'c' case 'c': player = SC.charAt(iC) player SC.charAt(iC) SC.charAt SC iC iC += 1 iC 1 break; System.out.println(String.valueOf(player).toUpperCase()) System.out.println System.out System System.out String.valueOf(player).toUpperCase() String.valueOf(player).toUpperCase String.valueOf(player) String.valueOf String player String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    }
} Main

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    }
}