import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    } main {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int a = 0 a 0 b = 0 b 0 c = 0; c 0 String as = in.nextLine(); as in.nextLine() in.nextLine in String bs = in.nextLine(); bs in.nextLine() in.nextLine in String cs = in.nextLine(); cs in.nextLine() in.nextLine in char now = 'a'; now 'a' while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        } true {
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        } switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            } now case 'a': 'a' case 'a': if(a == as.length()){
                    System.out.println("A");
                    return;
                } a == as.length() a as.length() as.length as {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; now= as.charAt(a++) now as.charAt(a++) as.charAt as a++ a break; case 'b': 'b' case 'b': if(b == bs.length()){
                    System.out.println("B");
                    return;
                } b == bs.length() b bs.length() bs.length bs {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; now= bs.charAt(b++) now bs.charAt(b++) bs.charAt bs b++ b break; case 'c': 'c' case 'c': if(c == cs.length()){
                    System.out.println("C");
                    return;
                } c == cs.length() c cs.length() cs.length cs {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; now= cs.charAt(c++) now cs.charAt(c++) cs.charAt cs c++ c break; String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    }
}