
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String a = sc.next(),b=sc.next(),c=sc.next();
        int ptA=0,ptB=0,ptC=0;

        char next = 'a';
        while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        }

        if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C';
        System.out.println(next);




    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String a = sc.next(),b=sc.next(),c=sc.next();
        int ptA=0,ptB=0,ptC=0;

        char next = 'a';
        while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        }

        if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C';
        System.out.println(next);




    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String a = sc.next(),b=sc.next(),c=sc.next();
        int ptA=0,ptB=0,ptC=0;

        char next = 'a';
        while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        }

        if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C';
        System.out.println(next);




    } main {

        Scanner sc = new Scanner(System.in);

        String a = sc.next(),b=sc.next(),c=sc.next();
        int ptA=0,ptB=0,ptC=0;

        char next = 'a';
        while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        }

        if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C';
        System.out.println(next);




    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next() a sc.next() sc.next sc b=sc.next() b sc.next() sc.next sc c=sc.next(); c sc.next() sc.next sc int ptA=0 ptA 0 ptB=0 ptB 0 ptC=0; ptC 0 char next = 'a'; next 'a' while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        } true {
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        } if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            } next == 'a' next 'a' {
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            } if(ptA==a.length())break; ptA==a.length() ptA a.length() a.length a break; next=a.charAt(ptA) next a.charAt(ptA) a.charAt a ptA ptA++ ptA if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            } next =='b' next 'b' {
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            } if(ptB==b.length())break; ptB==b.length() ptB b.length() b.length b break; next=b.charAt(ptB) next b.charAt(ptB) b.charAt b ptB ptB++ ptB {
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            } if(ptC==c.length())break; ptC==c.length() ptC c.length() c.length c break; next = c.charAt(ptC) next c.charAt(ptC) c.charAt c ptC ptC++ ptC if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C'; next =='a' next 'a' next='A' next 'A' if(next=='b')next='B';
        else next='C'; next=='b' next 'b' next='B' next 'B' next='C' next 'C' System.out.println(next) System.out.println System.out System System.out next String[] args args public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String a = sc.next(),b=sc.next(),c=sc.next();
        int ptA=0,ptB=0,ptC=0;

        char next = 'a';
        while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        }

        if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C';
        System.out.println(next);




    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String a = sc.next(),b=sc.next(),c=sc.next();
        int ptA=0,ptB=0,ptC=0;

        char next = 'a';
        while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        }

        if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C';
        System.out.println(next);




    }
} Main

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String a = sc.next(),b=sc.next(),c=sc.next();
        int ptA=0,ptB=0,ptC=0;

        char next = 'a';
        while(true){
            if(next == 'a'){
                if(ptA==a.length())break;
                next=a.charAt(ptA);
                ptA++;

            }else if(next =='b'){
                if(ptB==b.length())break;
                next=b.charAt(ptB);
                ptB++;

            }else{
                if(ptC==c.length())break;
                next = c.charAt(ptC);
                ptC++;

            }
        }

        if(next =='a')next='A';
        else if(next=='b')next='B';
        else next='C';
        System.out.println(next);




    }
}
