import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String sa = sc.next();
        String sb = sc.next();
        String scc = sc.next();
        int[] idx = new int[3];
        String[] can = new String[]{sa,sb,scc};
        int cur = 0;
        while(idx[cur]<can[cur].length()){
            int next = can[cur].charAt(idx[cur])-'a';
            idx[cur]++;
            cur=next;
        }
        String[] res = new String[]{"A","B","C"};
        System.out.println(res[cur]);
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String sa = sc.next();
        String sb = sc.next();
        String scc = sc.next();
        int[] idx = new int[3];
        String[] can = new String[]{sa,sb,scc};
        int cur = 0;
        while(idx[cur]<can[cur].length()){
            int next = can[cur].charAt(idx[cur])-'a';
            idx[cur]++;
            cur=next;
        }
        String[] res = new String[]{"A","B","C"};
        System.out.println(res[cur]);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String sa = sc.next();
        String sb = sc.next();
        String scc = sc.next();
        int[] idx = new int[3];
        String[] can = new String[]{sa,sb,scc};
        int cur = 0;
        while(idx[cur]<can[cur].length()){
            int next = can[cur].charAt(idx[cur])-'a';
            idx[cur]++;
            cur=next;
        }
        String[] res = new String[]{"A","B","C"};
        System.out.println(res[cur]);
    } main {
        Scanner sc = new Scanner(System.in);
        String sa = sc.next();
        String sb = sc.next();
        String scc = sc.next();
        int[] idx = new int[3];
        String[] can = new String[]{sa,sb,scc};
        int cur = 0;
        while(idx[cur]<can[cur].length()){
            int next = can[cur].charAt(idx[cur])-'a';
            idx[cur]++;
            cur=next;
        }
        String[] res = new String[]{"A","B","C"};
        System.out.println(res[cur]);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String sa = sc.next(); sa sc.next() sc.next sc String sb = sc.next(); sb sc.next() sc.next sc String scc = sc.next(); scc sc.next() sc.next sc int[] idx = new int[3]; idx new int[3] 3 String[] can = new String[]{sa,sb,scc}; can new String[]{sa,sb,scc} int cur = 0; cur 0 while(idx[cur]<can[cur].length()){
            int next = can[cur].charAt(idx[cur])-'a';
            idx[cur]++;
            cur=next;
        } idx[cur]<can[cur].length() idx[cur] idx cur can[cur].length() can[cur].length can[cur] can cur {
            int next = can[cur].charAt(idx[cur])-'a';
            idx[cur]++;
            cur=next;
        } int next = can[cur].charAt(idx[cur])-'a'; next can[cur].charAt(idx[cur])-'a' can[cur].charAt(idx[cur]) can[cur].charAt can[cur] can cur idx[cur] idx cur 'a' idx[cur]++ idx[cur] idx cur cur=next cur next String[] res = new String[]{"A","B","C"}; res new String[]{"A","B","C"} System.out.println(res[cur]) System.out.println System.out System System.out res[cur] res cur String[] args args
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String sa = sc.next();
        String sb = sc.next();
        String scc = sc.next();
        int[] idx = new int[3];
        String[] can = new String[]{sa,sb,scc};
        int cur = 0;
        while(idx[cur]<can[cur].length()){
            int next = can[cur].charAt(idx[cur])-'a';
            idx[cur]++;
            cur=next;
        }
        String[] res = new String[]{"A","B","C"};
        System.out.println(res[cur]);
    }
}
