import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();
        int ia = 0;
        int ib = 0;
        int ic = 0;
        char next = 'a';
        for(int i = 0; i<(sa.length()+sb.length()+sc.length()); i++) {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        }
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();
        int ia = 0;
        int ib = 0;
        int ic = 0;
        char next = 'a';
        for(int i = 0; i<(sa.length()+sb.length()+sc.length()); i++) {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();
        int ia = 0;
        int ib = 0;
        int ic = 0;
        char next = 'a';
        for(int i = 0; i<(sa.length()+sb.length()+sc.length()); i++) {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();
        int ia = 0;
        int ib = 0;
        int ic = 0;
        char next = 'a';
        for(int i = 0; i<(sa.length()+sb.length()+sc.length()); i++) {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String sa = scanner.next(); sa scanner.next() scanner.next scanner String sb = scanner.next(); sb scanner.next() scanner.next scanner String sc = scanner.next(); sc scanner.next() scanner.next scanner int ia = 0; ia 0 int ib = 0; ib 0 int ic = 0; ic 0 char next = 'a'; next 'a' for(int i = 0; i<(sa.length()+sb.length()+sc.length()); i++) {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        } int i = 0; int i = 0; i 0 i<(sa.length()+sb.length()+sc.length()) i (sa.length()+sb.length()+sc.length()) sa.length()+sb.length()+sc.length() sa.length() sa.length sa sb.length() sb.length sb sc.length() sc.length sc i++ i++ i {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        } {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        } if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            } next=='a' next 'a' {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            } if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                } ia == sa.length() ia sa.length() sa.length sa {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; next = sa.charAt(ia) next sa.charAt(ia) sa.charAt sa ia ia++ ia if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            } next=='b' next 'b' {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            } if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                } ib == sb.length() ib sb.length() sb.length sb {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; next = sb.charAt(ib) next sb.charAt(ib) sb.charAt sb ib ib++ ib {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            } if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                } ic == sc.length() ic sc.length() sc.length sc {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; next = sc.charAt(ic) next sc.charAt(ic) sc.charAt sc ic ic++ ic String[] args args
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String sa = scanner.next();
        String sb = scanner.next();
        String sc = scanner.next();
        int ia = 0;
        int ib = 0;
        int ic = 0;
        char next = 'a';
        for(int i = 0; i<(sa.length()+sb.length()+sc.length()); i++) {
            if(next=='a') {
                if(ia == sa.length()) {
                    System.out.println("A");
                    return;
                }
                next = sa.charAt(ia);
                ia++;
            }else if(next=='b') {
                if(ib == sb.length()) {
                    System.out.println("B");
                    return;
                }
                next = sb.charAt(ib);
                ib++;
            }else {
                if(ic == sc.length()) {
                    System.out.println("C");
                    return;
                }
                next = sc.charAt(ic);
                ic++;
            }
        }
    }
}