import java.io.*;
import java.util.*;

class Main {
    static char[] a, b, c;
    static int[] ids;
    static char res;
    
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ids = new int[3];
        a = br.readLine().toCharArray();
        b = br.readLine().toCharArray();
        c = br.readLine().toCharArray();
        recur(0, a);
        System.out.println(res);
    }
    
    static void recur(int id, char[] carr){
        if(ids[id]==carr.length){
            res = (char)(id+'A');
            return;
        }
        char curr = carr[ids[id]];
        ids[id]++;
        if(curr == 'a')
            recur(0, a);
        else if(curr == 'b')
            recur(1, b);
        else
            recur(2, c);
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {
    static char[] a, b, c;
    static int[] ids;
    static char res;
    
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ids = new int[3];
        a = br.readLine().toCharArray();
        b = br.readLine().toCharArray();
        c = br.readLine().toCharArray();
        recur(0, a);
        System.out.println(res);
    }
    
    static void recur(int id, char[] carr){
        if(ids[id]==carr.length){
            res = (char)(id+'A');
            return;
        }
        char curr = carr[ids[id]];
        ids[id]++;
        if(curr == 'a')
            recur(0, a);
        else if(curr == 'b')
            recur(1, b);
        else
            recur(2, c);
    }
} Main static char[] a a b b c; c static int[] ids; ids static char res; res public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ids = new int[3];
        a = br.readLine().toCharArray();
        b = br.readLine().toCharArray();
        c = br.readLine().toCharArray();
        recur(0, a);
        System.out.println(res);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ids = new int[3];
        a = br.readLine().toCharArray();
        b = br.readLine().toCharArray();
        c = br.readLine().toCharArray();
        recur(0, a);
        System.out.println(res);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) ids = new int[3] ids new int[3] 3 a = br.readLine().toCharArray() a br.readLine().toCharArray() br.readLine().toCharArray br.readLine() br.readLine br b = br.readLine().toCharArray() b br.readLine().toCharArray() br.readLine().toCharArray br.readLine() br.readLine br c = br.readLine().toCharArray() c br.readLine().toCharArray() br.readLine().toCharArray br.readLine() br.readLine br recur(0, a) recur 0 a System.out.println(res) System.out.println System.out System System.out res String args[] args static void recur(int id, char[] carr){
        if(ids[id]==carr.length){
            res = (char)(id+'A');
            return;
        }
        char curr = carr[ids[id]];
        ids[id]++;
        if(curr == 'a')
            recur(0, a);
        else if(curr == 'b')
            recur(1, b);
        else
            recur(2, c);
    } recur {
        if(ids[id]==carr.length){
            res = (char)(id+'A');
            return;
        }
        char curr = carr[ids[id]];
        ids[id]++;
        if(curr == 'a')
            recur(0, a);
        else if(curr == 'b')
            recur(1, b);
        else
            recur(2, c);
    } if(ids[id]==carr.length){
            res = (char)(id+'A');
            return;
        } ids[id]==carr.length ids[id] ids id carr.length carr carr.length {
            res = (char)(id+'A');
            return;
        } res = (char)(id+'A') res (char)(id+'A') id 'A' return; char curr = carr[ids[id]]; curr carr[ids[id]] carr ids[id] ids id ids[id]++ ids[id] ids id if(curr == 'a')
            recur(0, a);
        else if(curr == 'b')
            recur(1, b);
        else
            recur(2, c); curr == 'a' curr 'a' recur(0, a) recur 0 a if(curr == 'b')
            recur(1, b);
        else
            recur(2, c); curr == 'b' curr 'b' recur(1, b) recur 1 b recur(2, c) recur 2 c int id id char[] carr carr
import java.io.*;
import java.util.*;

class Main {
    static char[] a, b, c;
    static int[] ids;
    static char res;
    
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ids = new int[3];
        a = br.readLine().toCharArray();
        b = br.readLine().toCharArray();
        c = br.readLine().toCharArray();
        recur(0, a);
        System.out.println(res);
    }
    
    static void recur(int id, char[] carr){
        if(ids[id]==carr.length){
            res = (char)(id+'A');
            return;
        }
        char curr = carr[ids[id]];
        ids[id]++;
        if(curr == 'a')
            recur(0, a);
        else if(curr == 'b')
            recur(1, b);
        else
            recur(2, c);
    }
}