import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] players =  new String[3];
        for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        }

        int i=0, j=0, k=0;
        char c = 'a';
        while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] players =  new String[3];
        for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        }

        int i=0, j=0, k=0;
        char c = 'a';
        while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] players =  new String[3];
        for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        }

        int i=0, j=0, k=0;
        char c = 'a';
        while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        }
    } main {
        Scanner scan = new Scanner(System.in);
        String[] players =  new String[3];
        for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        }

        int i=0, j=0, k=0;
        char c = 'a';
        while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String[] players =  new String[3]; players new String[3] 3 for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        } int i=0; int i=0; i 0 i<3 i 3 i++ i++ i {
            players[i] = scan.nextLine();
        } {
            players[i] = scan.nextLine();
        } players[i] = scan.nextLine() players[i] players i scan.nextLine() scan.nextLine scan int i=0 i 0 j=0 j 0 k=0; k 0 char c = 'a'; c 'a' while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        } true {

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        } if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            } c == 'a' c 'a' {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            } if(i == players[0].length()){
                    System.out.println("A");
                    break;
                } i == players[0].length() i players[0].length() players[0].length players[0] players 0 {
                    System.out.println("A");
                    break;
                } System.out.println("A") System.out.println System.out System System.out "A" break; c = players[c - 'a'].charAt(i++) c players[c - 'a'].charAt(i++) players[c - 'a'].charAt players[c - 'a'] players c - 'a' c 'a' i++ i if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            } c == 'b' c 'b' {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            } if(j == players[1].length()){
                    System.out.println("B");
                    break;
                } j == players[1].length() j players[1].length() players[1].length players[1] players 1 {
                    System.out.println("B");
                    break;
                } System.out.println("B") System.out.println System.out System System.out "B" break; c = players[c - 'a'].charAt(j++) c players[c - 'a'].charAt(j++) players[c - 'a'].charAt players[c - 'a'] players c - 'a' c 'a' j++ j if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            } c == 'c' c 'c' {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            } if(k == players[2].length()){
                    System.out.println("C");
                    break;
                } k == players[2].length() k players[2].length() players[2].length players[2] players 2 {
                    System.out.println("C");
                    break;
                } System.out.println("C") System.out.println System.out System System.out "C" break; c = players[c - 'a'].charAt(k++) c players[c - 'a'].charAt(k++) players[c - 'a'].charAt players[c - 'a'] players c - 'a' c 'a' k++ k String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] players =  new String[3];
        for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        }

        int i=0, j=0, k=0;
        char c = 'a';
        while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] players =  new String[3];
        for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        }

        int i=0, j=0, k=0;
        char c = 'a';
        while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String[] players =  new String[3];
        for(int i=0; i<3; i++){
            players[i] = scan.nextLine();
        }

        int i=0, j=0, k=0;
        char c = 'a';
        while(true){

            if(c == 'a') {
                if(i == players[0].length()){
                    System.out.println("A");
                    break;
                }
                c = players[c - 'a'].charAt(i++);
            }
            if(c == 'b') {
                if(j == players[1].length()){
                    System.out.println("B");
                    break;
                }
                c = players[c - 'a'].charAt(j++);
            }
            if(c == 'c') {
                if(k == players[2].length()){
                    System.out.println("C");
                    break;
                }
                c = players[c - 'a'].charAt(k++);
            }

        }
    }
}