import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] array = new String[3];
        int[] cnt = new int[3]; 
        int i,j=0;
        for(i=0;i<3;i++) array[i] = sc.next();
        while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] array = new String[3];
        int[] cnt = new int[3]; 
        int i,j=0;
        for(i=0;i<3;i++) array[i] = sc.next();
        while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] array = new String[3];
        int[] cnt = new int[3]; 
        int i,j=0;
        for(i=0;i<3;i++) array[i] = sc.next();
        while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        }
    } main {
        Scanner sc = new Scanner(System.in);
        String[] array = new String[3];
        int[] cnt = new int[3]; 
        int i,j=0;
        for(i=0;i<3;i++) array[i] = sc.next();
        while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] array = new String[3]; array new String[3] 3 int[] cnt = new int[3]; cnt new int[3] 3 int i i j=0; j 0 for(i=0;i<3;i++) array[i] = sc.next(); i=0; i=0 i 0 i<3 i 3 i++ i++ i array[i] = sc.next(); array[i] = sc.next() array[i] array i sc.next() sc.next sc while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        } true {
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        } if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            } cnt[j]==array[j].length() cnt[j] cnt j array[j].length() array[j].length array[j] array j {
                System.out.println((char)(j+'A'));
                break;
            } System.out.println((char)(j+'A')) System.out.println System.out System System.out (char)(j+'A') j 'A' break; j = array[j].charAt(cnt[j]++)-'a' j array[j].charAt(cnt[j]++)-'a' array[j].charAt(cnt[j]++) array[j].charAt array[j] array j cnt[j]++ cnt[j] cnt j 'a' String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] array = new String[3];
        int[] cnt = new int[3]; 
        int i,j=0;
        for(i=0;i<3;i++) array[i] = sc.next();
        while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] array = new String[3];
        int[] cnt = new int[3]; 
        int i,j=0;
        for(i=0;i<3;i++) array[i] = sc.next();
        while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] array = new String[3];
        int[] cnt = new int[3]; 
        int i,j=0;
        for(i=0;i<3;i++) array[i] = sc.next();
        while(true){
            if(cnt[j]==array[j].length()){
                System.out.println((char)(j+'A'));
                break;
            }
            j = array[j].charAt(cnt[j]++)-'a';
        }
    }
}
