
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word1= s.next(),word2=s.next(),word3=s.next();
        Queue<Character>q1 = new ArrayDeque<>();
        Queue<Character>q2 = new ArrayDeque<>();
        Queue<Character>q3 = new ArrayDeque<>();
        for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i));
        for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i));
        for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i));
        char  g = 'a';
        while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        }




    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word1= s.next(),word2=s.next(),word3=s.next();
        Queue<Character>q1 = new ArrayDeque<>();
        Queue<Character>q2 = new ArrayDeque<>();
        Queue<Character>q3 = new ArrayDeque<>();
        for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i));
        for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i));
        for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i));
        char  g = 'a';
        while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        }




    }

} Main public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word1= s.next(),word2=s.next(),word3=s.next();
        Queue<Character>q1 = new ArrayDeque<>();
        Queue<Character>q2 = new ArrayDeque<>();
        Queue<Character>q3 = new ArrayDeque<>();
        for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i));
        for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i));
        for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i));
        char  g = 'a';
        while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        }




    } main {
        Scanner s = new Scanner(System.in);
        String word1= s.next(),word2=s.next(),word3=s.next();
        Queue<Character>q1 = new ArrayDeque<>();
        Queue<Character>q2 = new ArrayDeque<>();
        Queue<Character>q3 = new ArrayDeque<>();
        for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i));
        for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i));
        for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i));
        char  g = 'a';
        while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        }




    } Scanner s = new Scanner(System.in); s new Scanner(System.in) String word1= s.next() word1 s.next() s.next s word2=s.next() word2 s.next() s.next s word3=s.next(); word3 s.next() s.next s Queue<Character>q1 = new ArrayDeque<>(); q1 new ArrayDeque<>() Queue<Character>q2 = new ArrayDeque<>(); q2 new ArrayDeque<>() Queue<Character>q3 = new ArrayDeque<>(); q3 new ArrayDeque<>() for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i)); int i=0; int i=0; i 0 i<word1.length() i word1.length() word1.length word1 i++ i++ i q1.add(word1.charAt(i)); q1.add(word1.charAt(i)) q1.add q1 word1.charAt(i) word1.charAt word1 i for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i)); int i=0; int i=0; i 0 i<word2.length() i word2.length() word2.length word2 i++ i++ i q2.add(word2.charAt(i)); q2.add(word2.charAt(i)) q2.add q2 word2.charAt(i) word2.charAt word2 i for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i)); int i=0; int i=0; i 0 i<word3.length() i word3.length() word3.length word3 i++ i++ i q3.add(word3.charAt(i)); q3.add(word3.charAt(i)) q3.add q3 word3.charAt(i) word3.charAt word3 i char  g = 'a'; g 'a' while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        } true {
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        } if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            } g=='a' g 'a' {
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            } if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                } q1.isEmpty() q1.isEmpty q1 {
                    System.out.println('A');
                    break;
                } System.out.println('A') System.out.println System.out System System.out 'A' break; {
                    g = q1.poll();
                } g = q1.poll() g q1.poll() q1.poll q1 if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            } g=='b' g 'b' {
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            } if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                } q2.isEmpty() q2.isEmpty q2 {
                    System.out.println('B');
                    break;
                } System.out.println('B') System.out.println System.out System System.out 'B' break; {
                    g = q2.poll();
                } g = q2.poll() g q2.poll() q2.poll q2 {
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            } if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                } q3.isEmpty() q3.isEmpty q3 {
                    System.out.println('C');
                    break;
                } System.out.println('C') System.out.println System.out System System.out 'C' break; {
                    g = q3.poll();
                } g = q3.poll() g q3.poll() q3.poll q3 String[] args args class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


} Scanner StringTokenizer st; st BufferedReader br; br public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));} Scanner {	br = new BufferedReader(new InputStreamReader(s));} br = new BufferedReader(new InputStreamReader(s)) br new BufferedReader(new InputStreamReader(s)) InputStream s s public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    } next {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    } while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine()); st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() throws IOException {return Integer.parseInt(next());} nextInt {return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() throws IOException {return Long.parseLong(next());} nextLong {return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public String nextLine() throws IOException {return br.readLine();} nextLine {return br.readLine();} return br.readLine(); br.readLine() br.readLine br public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    } nextDouble {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    } String x = next(); x next() next StringBuilder sb = new StringBuilder("0"); sb new StringBuilder("0") double res = 0 res 0 f = 1; f 1 boolean dec = false dec false neg = false; neg false int start = 0; start 0 if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        } x.charAt(0) == '-' x.charAt(0) x.charAt x 0 '-' {
            neg = true;
            start++;
        } neg = true neg true start++ start for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            } int i = start; int i = start; i start i < x.length() i x.length() x.length x i++ i++ i if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            } if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            } x.charAt(i) == '.' x.charAt(i) x.charAt x i '.' {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            } res = Long.parseLong(sb.toString()) res Long.parseLong(sb.toString()) Long.parseLong Long sb.toString() sb.toString sb sb = new StringBuilder("0") sb new StringBuilder("0") dec = true dec true {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            } sb.append(x.charAt(i)) sb.append sb x.charAt(i) x.charAt x i if(dec)
                    f *= 10; dec f *= 10 f 10 res += Long.parseLong(sb.toString()) / f res Long.parseLong(sb.toString()) / f Long.parseLong(sb.toString()) Long.parseLong Long sb.toString() sb.toString sb f return res * (neg?-1:1); res * (neg?-1:1) res (neg?-1:1) neg -1 1 1 public boolean ready() throws IOException {return br.ready();} ready {return br.ready();} return br.ready(); br.ready() br.ready br public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word1= s.next(),word2=s.next(),word3=s.next();
        Queue<Character>q1 = new ArrayDeque<>();
        Queue<Character>q2 = new ArrayDeque<>();
        Queue<Character>q3 = new ArrayDeque<>();
        for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i));
        for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i));
        for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i));
        char  g = 'a';
        while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        }




    }

} public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word1= s.next(),word2=s.next(),word3=s.next();
        Queue<Character>q1 = new ArrayDeque<>();
        Queue<Character>q2 = new ArrayDeque<>();
        Queue<Character>q3 = new ArrayDeque<>();
        for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i));
        for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i));
        for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i));
        char  g = 'a';
        while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        }




    }

} Main

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word1= s.next(),word2=s.next(),word3=s.next();
        Queue<Character>q1 = new ArrayDeque<>();
        Queue<Character>q2 = new ArrayDeque<>();
        Queue<Character>q3 = new ArrayDeque<>();
        for(int i=0;i<word1.length();i++)q1.add(word1.charAt(i));
        for(int i=0;i<word2.length();i++)q2.add(word2.charAt(i));
        for(int i=0;i<word3.length();i++)q3.add(word3.charAt(i));
        char  g = 'a';
        while(true){
            if(g=='a'){
                if(q1.isEmpty()){
                    System.out.println('A');
                    break;
                }
                else{
                    g = q1.poll();
                }
            }
            else if(g=='b'){
                if(q2.isEmpty()){
                    System.out.println('B');
                    break;
                }
                else{
                    g = q2.poll();
                }
            }
            else{
                if(q3.isEmpty()){
                    System.out.println('C');
                    break;
                }
                else{
                    g = q3.poll();
                }
            }
        }




    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}