import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0; i < 3; i++) s[i] = sc.next();
        int[] size = new int[3];
        for (int i = 0; i < 3; i++) size[i] = s[i].length();
        int[] cursor = new int[3];
        char ch = 'a';
        while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0; i < 3; i++) s[i] = sc.next();
        int[] size = new int[3];
        for (int i = 0; i < 3; i++) size[i] = s[i].length();
        int[] cursor = new int[3];
        char ch = 'a';
        while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0; i < 3; i++) s[i] = sc.next();
        int[] size = new int[3];
        for (int i = 0; i < 3; i++) size[i] = s[i].length();
        int[] cursor = new int[3];
        char ch = 'a';
        while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0; i < 3; i++) s[i] = sc.next();
        int[] size = new int[3];
        for (int i = 0; i < 3; i++) size[i] = s[i].length();
        int[] cursor = new int[3];
        char ch = 'a';
        while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] s = new String[3]; s new String[3] 3 for (int i = 0; i < 3; i++) s[i] = sc.next(); int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i s[i] = sc.next(); s[i] = sc.next() s[i] s i sc.next() sc.next sc int[] size = new int[3]; size new int[3] 3 for (int i = 0; i < 3; i++) size[i] = s[i].length(); int i = 0; int i = 0; i 0 i < 3 i 3 i++ i++ i size[i] = s[i].length(); size[i] = s[i].length() size[i] size i s[i].length() s[i].length s[i] s i int[] cursor = new int[3]; cursor new int[3] 3 char ch = 'a'; ch 'a' while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        } true {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        } int n = ch - 'a'; n ch - 'a' ch 'a' if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            } cursor[n] >= size[n] cursor[n] cursor n size[n] size n {
                System.out.println((char) ('A' + n));
                return;
            } System.out.println((char) ('A' + n)) System.out.println System.out System System.out (char) ('A' + n) 'A' n return; {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            } ch = s[n].charAt(cursor[n]) ch s[n].charAt(cursor[n]) s[n].charAt s[n] s n cursor[n] cursor n cursor[n]++ cursor[n] cursor n String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0; i < 3; i++) s[i] = sc.next();
        int[] size = new int[3];
        for (int i = 0; i < 3; i++) size[i] = s[i].length();
        int[] cursor = new int[3];
        char ch = 'a';
        while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0; i < 3; i++) s[i] = sc.next();
        int[] size = new int[3];
        for (int i = 0; i < 3; i++) size[i] = s[i].length();
        int[] cursor = new int[3];
        char ch = 'a';
        while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        }
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = new String[3];
        for (int i = 0; i < 3; i++) s[i] = sc.next();
        int[] size = new int[3];
        for (int i = 0; i < 3; i++) size[i] = s[i].length();
        int[] cursor = new int[3];
        char ch = 'a';
        while (true) {
            int n = ch - 'a';
            if (cursor[n] >= size[n]) {
                System.out.println((char) ('A' + n));
                return;
            } else {
                ch = s[n].charAt(cursor[n]);
                cursor[n]++;
            }
        }
    }
}