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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        StringBuffer str;
        String S_a, S_b, S_c, Sr_a, Sr_b, Sr_c;
        char card;

        S_a = sc.nextLine();
        S_b = sc.nextLine();
        S_c = sc.nextLine();

        str = new StringBuffer(S_a);
        Sr_a = str.reverse().toString();

        str = new StringBuffer(S_b);
        Sr_b = str.reverse().toString();

        str = new StringBuffer(S_c);
        Sr_c = str.reverse().toString();

        card = Sr_a.charAt(Sr_a.length()-1);
        Sr_a = Sr_a.substring(0, Sr_a.length() -1 );
        
        while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        }

        card -= 32;
        out.println(Character.toString(card));
        
        
        sc.close();
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        StringBuffer str;
        String S_a, S_b, S_c, Sr_a, Sr_b, Sr_c;
        char card;

        S_a = sc.nextLine();
        S_b = sc.nextLine();
        S_c = sc.nextLine();

        str = new StringBuffer(S_a);
        Sr_a = str.reverse().toString();

        str = new StringBuffer(S_b);
        Sr_b = str.reverse().toString();

        str = new StringBuffer(S_c);
        Sr_c = str.reverse().toString();

        card = Sr_a.charAt(Sr_a.length()-1);
        Sr_a = Sr_a.substring(0, Sr_a.length() -1 );
        
        while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        }

        card -= 32;
        out.println(Character.toString(card));
        
        
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        StringBuffer str;
        String S_a, S_b, S_c, Sr_a, Sr_b, Sr_c;
        char card;

        S_a = sc.nextLine();
        S_b = sc.nextLine();
        S_c = sc.nextLine();

        str = new StringBuffer(S_a);
        Sr_a = str.reverse().toString();

        str = new StringBuffer(S_b);
        Sr_b = str.reverse().toString();

        str = new StringBuffer(S_c);
        Sr_c = str.reverse().toString();

        card = Sr_a.charAt(Sr_a.length()-1);
        Sr_a = Sr_a.substring(0, Sr_a.length() -1 );
        
        while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        }

        card -= 32;
        out.println(Character.toString(card));
        
        
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        StringBuffer str;
        String S_a, S_b, S_c, Sr_a, Sr_b, Sr_c;
        char card;

        S_a = sc.nextLine();
        S_b = sc.nextLine();
        S_c = sc.nextLine();

        str = new StringBuffer(S_a);
        Sr_a = str.reverse().toString();

        str = new StringBuffer(S_b);
        Sr_b = str.reverse().toString();

        str = new StringBuffer(S_c);
        Sr_c = str.reverse().toString();

        card = Sr_a.charAt(Sr_a.length()-1);
        Sr_a = Sr_a.substring(0, Sr_a.length() -1 );
        
        while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        }

        card -= 32;
        out.println(Character.toString(card));
        
        
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintStream out = new PrintStream(System.out); out new PrintStream(System.out) StringBuffer str; str String S_a S_a S_b S_b S_c S_c Sr_a Sr_a Sr_b Sr_b Sr_c; Sr_c char card; card S_a = sc.nextLine() S_a sc.nextLine() sc.nextLine sc S_b = sc.nextLine() S_b sc.nextLine() sc.nextLine sc S_c = sc.nextLine() S_c sc.nextLine() sc.nextLine sc str = new StringBuffer(S_a) str new StringBuffer(S_a) Sr_a = str.reverse().toString() Sr_a str.reverse().toString() str.reverse().toString str.reverse() str.reverse str str = new StringBuffer(S_b) str new StringBuffer(S_b) Sr_b = str.reverse().toString() Sr_b str.reverse().toString() str.reverse().toString str.reverse() str.reverse str str = new StringBuffer(S_c) str new StringBuffer(S_c) Sr_c = str.reverse().toString() Sr_c str.reverse().toString() str.reverse().toString str.reverse() str.reverse str card = Sr_a.charAt(Sr_a.length()-1) card Sr_a.charAt(Sr_a.length()-1) Sr_a.charAt Sr_a Sr_a.length()-1 Sr_a.length() Sr_a.length Sr_a 1 Sr_a = Sr_a.substring(0, Sr_a.length() -1 ) Sr_a Sr_a.substring(0, Sr_a.length() -1 ) Sr_a.substring Sr_a 0 Sr_a.length() -1 Sr_a.length() Sr_a.length Sr_a 1 while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        } !Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty() !Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty() !Sr_a.isEmpty() Sr_a.isEmpty() Sr_a.isEmpty Sr_a !Sr_b.isEmpty() Sr_b.isEmpty() Sr_b.isEmpty Sr_b !Sr_c.isEmpty() Sr_c.isEmpty() Sr_c.isEmpty Sr_c {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        } if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            } card == 'a' card 'a' {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } if(Sr_a.isEmpty()) break; Sr_a.isEmpty() Sr_a.isEmpty Sr_a break; card = Sr_a.charAt(Sr_a.length()-1) card Sr_a.charAt(Sr_a.length()-1) Sr_a.charAt Sr_a Sr_a.length()-1 Sr_a.length() Sr_a.length Sr_a 1 Sr_a = Sr_a.substring(0, Sr_a.length() -1 ) Sr_a Sr_a.substring(0, Sr_a.length() -1 ) Sr_a.substring Sr_a 0 Sr_a.length() -1 Sr_a.length() Sr_a.length Sr_a 1 continue; if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            } card == 'b' card 'b' {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } if(Sr_b.isEmpty()) break; Sr_b.isEmpty() Sr_b.isEmpty Sr_b break; card = Sr_b.charAt(Sr_b.length()-1) card Sr_b.charAt(Sr_b.length()-1) Sr_b.charAt Sr_b Sr_b.length()-1 Sr_b.length() Sr_b.length Sr_b 1 Sr_b = Sr_b.substring(0, Sr_b.length() -1 ) Sr_b Sr_b.substring(0, Sr_b.length() -1 ) Sr_b.substring Sr_b 0 Sr_b.length() -1 Sr_b.length() Sr_b.length Sr_b 1 continue; if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            } card == 'c' card 'c' {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            } if(Sr_c.isEmpty()) break; Sr_c.isEmpty() Sr_c.isEmpty Sr_c break; card = Sr_c.charAt(Sr_c.length()-1) card Sr_c.charAt(Sr_c.length()-1) Sr_c.charAt Sr_c Sr_c.length()-1 Sr_c.length() Sr_c.length Sr_c 1 Sr_c = Sr_c.substring(0, Sr_c.length() -1 ) Sr_c Sr_c.substring(0, Sr_c.length() -1 ) Sr_c.substring Sr_c 0 Sr_c.length() -1 Sr_c.length() Sr_c.length Sr_c 1 continue; card -= 32 card 32 out.println(Character.toString(card)) out.println out Character.toString(card) Character.toString Character card sc.close() sc.close sc String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        StringBuffer str;
        String S_a, S_b, S_c, Sr_a, Sr_b, Sr_c;
        char card;

        S_a = sc.nextLine();
        S_b = sc.nextLine();
        S_c = sc.nextLine();

        str = new StringBuffer(S_a);
        Sr_a = str.reverse().toString();

        str = new StringBuffer(S_b);
        Sr_b = str.reverse().toString();

        str = new StringBuffer(S_c);
        Sr_c = str.reverse().toString();

        card = Sr_a.charAt(Sr_a.length()-1);
        Sr_a = Sr_a.substring(0, Sr_a.length() -1 );
        
        while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        }

        card -= 32;
        out.println(Character.toString(card));
        
        
        sc.close();
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        StringBuffer str;
        String S_a, S_b, S_c, Sr_a, Sr_b, Sr_c;
        char card;

        S_a = sc.nextLine();
        S_b = sc.nextLine();
        S_c = sc.nextLine();

        str = new StringBuffer(S_a);
        Sr_a = str.reverse().toString();

        str = new StringBuffer(S_b);
        Sr_b = str.reverse().toString();

        str = new StringBuffer(S_c);
        Sr_c = str.reverse().toString();

        card = Sr_a.charAt(Sr_a.length()-1);
        Sr_a = Sr_a.substring(0, Sr_a.length() -1 );
        
        while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        }

        card -= 32;
        out.println(Character.toString(card));
        
        
        sc.close();
    }
} Main
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);

        StringBuffer str;
        String S_a, S_b, S_c, Sr_a, Sr_b, Sr_c;
        char card;

        S_a = sc.nextLine();
        S_b = sc.nextLine();
        S_c = sc.nextLine();

        str = new StringBuffer(S_a);
        Sr_a = str.reverse().toString();

        str = new StringBuffer(S_b);
        Sr_b = str.reverse().toString();

        str = new StringBuffer(S_c);
        Sr_c = str.reverse().toString();

        card = Sr_a.charAt(Sr_a.length()-1);
        Sr_a = Sr_a.substring(0, Sr_a.length() -1 );
        
        while (!Sr_a.isEmpty() || !Sr_b.isEmpty() || !Sr_c.isEmpty()) {
            if(card == 'a') {
                if(Sr_a.isEmpty()) break;

                card = Sr_a.charAt(Sr_a.length()-1);
                Sr_a = Sr_a.substring(0, Sr_a.length() -1 );

                
                continue;
            } else if(card == 'b') {
                if(Sr_b.isEmpty()) break;

                card = Sr_b.charAt(Sr_b.length()-1);
                Sr_b = Sr_b.substring(0, Sr_b.length() -1 );

                continue;
            } else if(card == 'c') {
                if(Sr_c.isEmpty()) break;

                card = Sr_c.charAt(Sr_c.length()-1);
                Sr_c = Sr_c.substring(0, Sr_c.length() -1 );

                continue;
            }
        }

        card -= 32;
        out.println(Character.toString(card));
        
        
        sc.close();
    }
}