import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);
    long[] arr = new long[(int)1e5];

    public static void main(String[] args){
        new Main().run();
    }

    void run() {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    }


} import java.util.*; util.* java public class Main{

    Scanner sc = new Scanner(System.in);
    long[] arr = new long[(int)1e5];

    public static void main(String[] args){
        new Main().run();
    }

    void run() {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    }


} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long[] arr = new long[(int)1e5]; arr new long[(int)1e5] (int)1e5 public static void main(String[] args){
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args void run() {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    } run {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    } 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 int s = 0; s 0 while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        } true {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        } if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            } s == 0 s 0 {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } if (a.length() == 0) {
                    System.out.println("A");
                    return;
                } a.length() == 0 a.length() a.length a 0 {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                } a.charAt(0) == 'a' a.charAt(0) a.charAt a 0 'a' {
                    s = 0;
                } s = 0 s 0 if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                } a.charAt(0) == 'b' a.charAt(0) a.charAt a 0 'b' {
                    s = 1;
                } s = 1 s 1 {
                    s = 2;
                } s = 2 s 2 a = a.substring(1, a.length()) a a.substring(1, a.length()) a.substring a 1 a.length() a.length a if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            } s == 1 s 1 {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } if (b.length() == 0) {
                    System.out.println("B");
                    return;
                } b.length() == 0 b.length() b.length b 0 {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                } b.charAt(0) == 'a' b.charAt(0) b.charAt b 0 'a' {
                    s = 0;
                } s = 0 s 0 if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                } b.charAt(0) == 'b' b.charAt(0) b.charAt b 0 'b' {
                    s = 1;
                } s = 1 s 1 {
                    s = 2;
                } s = 2 s 2 b = b.substring(1, b.length()) b b.substring(1, b.length()) b.substring b 1 b.length() b.length b {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            } if (c.length() == 0) {
                    System.out.println("C");
                    return;
                } c.length() == 0 c.length() c.length c 0 {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                } c.charAt(0) == 'a' c.charAt(0) c.charAt c 0 'a' {
                    s = 0;
                } s = 0 s 0 if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                } c.charAt(0) == 'b' c.charAt(0) c.charAt c 0 'b' {
                    s = 1;
                } s = 1 s 1 {
                    s = 2;
                } s = 2 s 2 c = c.substring(1, c.length()) c c.substring(1, c.length()) c.substring c 1 c.length() c.length c public class Main{

    Scanner sc = new Scanner(System.in);
    long[] arr = new long[(int)1e5];

    public static void main(String[] args){
        new Main().run();
    }

    void run() {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    }


} public class Main{

    Scanner sc = new Scanner(System.in);
    long[] arr = new long[(int)1e5];

    public static void main(String[] args){
        new Main().run();
    }

    void run() {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    }


} Main
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);
    long[] arr = new long[(int)1e5];

    public static void main(String[] args){
        new Main().run();
    }

    void run() {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        int s = 0;
        while (true) {
            if (s == 0) {
                if (a.length() == 0) {
                    System.out.println("A");
                    return;
                }
                if (a.charAt(0) == 'a') {
                    s = 0;
                } else if (a.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                a = a.substring(1, a.length());

            } else if (s == 1) {
                if (b.length() == 0) {
                    System.out.println("B");
                    return;
                }
                if (b.charAt(0) == 'a') {
                    s = 0;
                } else if (b.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                b = b.substring(1, b.length());
            } else {
                if (c.length() == 0) {
                    System.out.println("C");
                    return;
                }
                if (c.charAt(0) == 'a') {
                    s = 0;
                } else if (c.charAt(0) == 'b') {
                    s = 1;
                } else {
                    s = 2;
                }
                c = c.substring(1, c.length());
            }
        }

    }


}
