import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    } main {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String a = scan.next(); a scan.next() scan.next scan String b = scan.next(); b scan.next() scan.next scan String c = scan.next(); c scan.next() scan.next scan Integer ia = 0 ia 0 ib = 0 ib 0 ic = 0; ic 0 char d = 'a'; d 'a' while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        } true {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        } if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            } d == 'a' d 'a' {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                } ia >= a.length() ia a.length() a.length a {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; d = a.charAt(ia++) d a.charAt(ia++) a.charAt a ia++ ia if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            } d == 'b' d 'b' {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                } ib >= b.length() ib b.length() b.length b {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; d = b.charAt(ib++) d b.charAt(ib++) b.charAt b ib++ ib {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            } if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                } ic >= c.length() ic c.length() c.length c {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; d = c.charAt(ic++) d c.charAt(ic++) c.charAt c ic++ ic String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        Integer ia = 0, ib = 0, ic = 0;

        char d = 'a';
        while(true) {
            if (d == 'a') {
                if (ia >= a.length()) {
                    System.out.println("A");
                    return;
                }
                d = a.charAt(ia++);
            } else if (d == 'b') {
                if (ib >= b.length()) {
                    System.out.println("B");
                    return;
                }
                d = b.charAt(ib++);
            } else {
                if (ic >= c.length()) {
                    System.out.println("C");
                    return;
                }
                d = c.charAt(ic++);
            }
        }
    }
}
