import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char turn = 'a';
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int aCur = 0;
        int bCur = 0;
        int cCur = 0;
        for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        }


    }

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char turn = 'a';
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int aCur = 0;
        int bCur = 0;
        int cCur = 0;
        for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        }


    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char turn = 'a';
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int aCur = 0;
        int bCur = 0;
        int cCur = 0;
        for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        }


    } main {
        Scanner sc = new Scanner(System.in);
        char turn = 'a';
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int aCur = 0;
        int bCur = 0;
        int cCur = 0;
        for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        }


    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char turn = 'a'; turn 'a' 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 aCur = 0; aCur 0 int bCur = 0; bCur 0 int cCur = 0; cCur 0 for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        } int i = 0 ; int i = 0 ; i 0 i < 300 i 300 i++ i++ i {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        } {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        } if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            } turn == 'a' turn 'a' {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                } aCur == a.length() aCur a.length() a.length a {
                    System.out.println("A");
                    return;
                } System.out.println("A") System.out.println System.out System System.out "A" return; turn = a.charAt(aCur) turn a.charAt(aCur) a.charAt a aCur aCur++ aCur if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            } turn == 'b' turn 'b' {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                } bCur == b.length() bCur b.length() b.length b {
                    System.out.println("B");
                    return;
                } System.out.println("B") System.out.println System.out System System.out "B" return; turn = b.charAt(bCur) turn b.charAt(bCur) b.charAt b bCur bCur++ bCur {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            } if (cCur == c.length()){
                    System.out.println("C");
                    return;
                } cCur == c.length() cCur c.length() c.length c {
                    System.out.println("C");
                    return;
                } System.out.println("C") System.out.println System.out System System.out "C" return; turn = c.charAt(cCur) turn c.charAt(cCur) c.charAt c cCur cCur++ cCur String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char turn = 'a';
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int aCur = 0;
        int bCur = 0;
        int cCur = 0;
        for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        }


    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char turn = 'a';
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int aCur = 0;
        int bCur = 0;
        int cCur = 0;
        for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        }


    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char turn = 'a';
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        int aCur = 0;
        int bCur = 0;
        int cCur = 0;
        for (int i = 0 ; i < 300 ; i++) {

            if (turn == 'a') {
                if (aCur == a.length()) {
                    System.out.println("A");
                    return;
                }
                turn = a.charAt(aCur);
                aCur++;
            } else if (turn == 'b') {
                if (bCur == b.length()) {
                    System.out.println("B");
                    return;
                }
                turn = b.charAt(bCur);
                bCur++;
            } else {
                if (cCur == c.length()){
                    System.out.println("C");
                    return;
                }
                turn = c.charAt(cCur);
                cCur++;
            }
        }


    }

}