
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);




    }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz