import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S_a = sc.nextLine();
        String S_b = sc.nextLine();
        String S_c = sc.nextLine();
        sc.close();

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    }

} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S_a = sc.nextLine();
        String S_b = sc.nextLine();
        String S_c = sc.nextLine();
        sc.close();

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S_a = sc.nextLine();
        String S_b = sc.nextLine();
        String S_c = sc.nextLine();
        sc.close();

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        String S_a = sc.nextLine();
        String S_b = sc.nextLine();
        String S_c = sc.nextLine();
        sc.close();

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S_a = sc.nextLine(); S_a sc.nextLine() sc.nextLine sc String S_b = sc.nextLine(); S_b sc.nextLine() sc.nextLine sc String S_c = sc.nextLine(); S_c sc.nextLine() sc.nextLine sc sc.close() sc.close sc int i_a = 0; i_a 0 int i_b = 0; i_b 0 int i_c = 0; i_c 0 char next = 'a'; next 'a' String ans = ""; ans "" while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        } true {
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        } if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            } next == 'a' next 'a' {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                } i_a == S_a.length() i_a S_a.length() S_a.length S_a {
                    ans = "A";
                    break;
                } ans = "A" ans "A" break; {
                    next = S_a.charAt(i_a);
                    i_a++;
                } next = S_a.charAt(i_a) next S_a.charAt(i_a) S_a.charAt S_a i_a i_a++ i_a if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            } next == 'b' next 'b' {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                } i_b == S_b.length() i_b S_b.length() S_b.length S_b {
                    ans = "B";
                    break;
                } ans = "B" ans "B" break; {
                    next = S_b.charAt(i_b);
                    i_b++;
                } next = S_b.charAt(i_b) next S_b.charAt(i_b) S_b.charAt S_b i_b i_b++ i_b {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            } if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                } i_c == S_c.length() i_c S_c.length() S_c.length S_c {
                    ans = "C";
                    break;
                } ans = "C" ans "C" break; {
                    next = S_c.charAt(i_c);
                    i_c++;
                } next = S_c.charAt(i_c) next S_c.charAt(i_c) S_c.charAt S_c i_c i_c++ i_c 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 S_a = sc.nextLine();
        String S_b = sc.nextLine();
        String S_c = sc.nextLine();
        sc.close();

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    }

} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S_a = sc.nextLine();
        String S_b = sc.nextLine();
        String S_c = sc.nextLine();
        sc.close();

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    }

} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S_a = sc.nextLine();
        String S_b = sc.nextLine();
        String S_c = sc.nextLine();
        sc.close();

        int i_a = 0;
        int i_b = 0;
        int i_c = 0;

        char next = 'a';
        String ans = "";

        while(true){
            if(next == 'a') {
                if(i_a == S_a.length()) {
                    ans = "A";
                    break;
                } else {
                    next = S_a.charAt(i_a);
                    i_a++;
                }
            } else if(next == 'b') {
                if(i_b == S_b.length()) {
                    ans = "B";
                    break;
                } else {
                    next = S_b.charAt(i_b);
                    i_b++;
                }
            } else {
                if(i_c == S_c.length()) {
                    ans = "C";
                    break;
                } else{
                    next = S_c.charAt(i_c);
                    i_c++;
                }
            }
        }
        System.out.println(ans);
    }

}