import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    } main {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next(); a sc.next() sc.next sc String b = sc.next(); b sc.next() sc.next sc String c = sc.next(); c sc.next() sc.next sc char[] ac = a.toCharArray(); ac a.toCharArray() a.toCharArray a char[] bc = b.toCharArray(); bc b.toCharArray() b.toCharArray b char[] cc = c.toCharArray(); cc c.toCharArray() c.toCharArray c int ai = 0; ai 0 int bi = 0; bi 0 int ci = 0; ci 0 char winner = 'a'; winner 'a' char x = ac[ai]; x ac[ai] ac ai while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        } true {
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        } if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            } x == 'a' x 'a' {
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            } if(ai >= a.length()){
                    winner = 'A';
                    break;
                } ai >= a.length() ai a.length() a.length a {
                    winner = 'A';
                    break;
                } winner = 'A' winner 'A' break; x = ac[ai] x ac[ai] ac ai ai++ ai if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            } x == 'b' x 'b' {
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            } if(bi >= b.length()){
                    winner = 'B';
                    break;
                } bi >= b.length() bi b.length() b.length b {
                    winner = 'B';
                    break;
                } winner = 'B' winner 'B' break; x = bc[bi] x bc[bi] bc bi bi++ bi if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            } x == 'c' x 'c' {
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            } if(ci >= c.length()){
                    winner = 'C';
                    break;
                } ci >= c.length() ci c.length() c.length c {
                    winner = 'C';
                    break;
                } winner = 'C' winner 'C' break; x = cc[ci] x cc[ci] cc ci ci++ ci System.out.println(winner) System.out.println System.out System System.out winner String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        char[] ac = a.toCharArray();
        char[] bc = b.toCharArray();
        char[] cc = c.toCharArray();
        int ai = 0;
        int bi = 0;
        int ci = 0;
        char winner = 'a';
        char x = ac[ai];
        while(true){
            if(x == 'a'){
                if(ai >= a.length()){
                    winner = 'A';
                    break;
                }
                x = ac[ai];
                ai++;
            }
            if(x == 'b'){
                if(bi >= b.length()){
                    winner = 'B';
                    break;
                }
                x = bc[bi];
                bi++;
            }
            if(x == 'c'){
                if(ci >= c.length()){
                    winner = 'C';
                    break;
                }
                x = cc[ci];
                ci++;
            }
        }
        System.out.println(winner);
    }
}
