import java.util.Scanner;
public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
} Main public static Scanner scan  = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[]args){
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    } main {
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    } String [] abc = new String[3]; abc new String[3] 3 abc[0]=next() abc[0] abc 0 next() next abc[1]=next() abc[1] abc 1 next() next abc[2]=next() abc[2] abc 2 next() next int[] i_abc={0,0,0}; i_abc {0,0,0} 0 0 0 int now=0; now 0 char tmp; tmp while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        } true {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        } if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break; i_abc[now]<abc[now].length() i_abc[now] i_abc now abc[now].length() abc[now].length abc[now] abc now tmp=abc[now].charAt(i_abc[now]) tmp abc[now].charAt(i_abc[now]) abc[now].charAt abc[now] abc now i_abc[now] i_abc now break; i_abc[now]+=1 i_abc[now] i_abc now 1 switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            } tmp case 'a': 'a' case 'a': now=0 now 0 break; case 'b': 'b' case 'b': now=1 now 1 break; case 'c': 'c' case 'c': now=2 now 2 break; switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        } now case 0: 0 case 0: print("A") print "A" break; case 1: 1 case 1: print("B") print "B" break; case 2: 2 case 2: print("C") print "C" break; String[]args args public static int nextInt(){
        return Integer.parseInt(scan.next());
    } nextInt {
        return Integer.parseInt(scan.next());
    } return Integer.parseInt(scan.next()); Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan public static long nextLong(){
        return Long.parseLong(scan.next());
    } nextLong {
        return Long.parseLong(scan.next());
    } return Long.parseLong(scan.next()); Long.parseLong(scan.next()) Long.parseLong Long scan.next() scan.next scan public static String next(){
        return scan.next();
    } next {
        return scan.next();
    } return scan.next(); scan.next() scan.next scan public static double nextDouble(){
        return Double.parseDouble(scan.next());
    } nextDouble {
        return Double.parseDouble(scan.next());
    } return Double.parseDouble(scan.next()); Double.parseDouble(scan.next()) Double.parseDouble Double scan.next() scan.next scan public static float nextFloat(){
        return Float.parseFloat(scan.next());
    } nextFloat {
        return Float.parseFloat(scan.next());
    } return Float.parseFloat(scan.next()); Float.parseFloat(scan.next()) Float.parseFloat Float scan.next() scan.next scan //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    } yesNo {
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    } if(flag) System.out.println("Yes");
        else System.out.println("No"); flag System.out.println("Yes") System.out.println System.out System System.out "Yes" System.out.println("No") System.out.println System.out System System.out "No" boolean flag flag public static void print(Object a){
        System.out.println(a);
    } print {
        System.out.println(a);
    } System.out.println(a) System.out.println System.out System System.out a Object a a public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
} public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
} Main
import java.util.Scanner;
public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String [] abc = new String[3];
        abc[0]=next();
        abc[1]=next();
        abc[2]=next();
        int[] i_abc={0,0,0};
        int now=0;
        char tmp;

        while/*(
            i_abc[0]<=abc[0].length()&&
            i_abc[1]<=abc[1].length()&&
            i_abc[2]<=abc[2].length()
            )*/
            (true)
        {

            if(i_abc[now]<abc[now].length()) tmp=abc[now].charAt(i_abc[now]);
            else break;
            i_abc[now]+=1;
            switch (tmp){
                case 'a':
                    now=0;
                    break;
                case 'b':
                    now=1;
                    break;
                case 'c':
                    now=2;
                    break;
            }
        }
        /*
        if(i_abc[0]>=abc[0].length()) print('A');
        else if(i_abc[1]>=abc[1].length()) print('B');
        else if(i_abc[2]>=abc[2].length()) print('C');
        */
        switch(now){
            case 0:
                print("A");
                break;
            case 1:
                print("B");
                break;
            case 2:
                print("C");
                break;
        }
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}
