import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder a = new StringBuilder(scan.next());
        StringBuilder b = new StringBuilder(scan.next());
        StringBuilder c = new StringBuilder(scan.next());
        boolean hantei = true;
        char turn = a.charAt(0);
        a.deleteCharAt(0);
        char ans = ' ';

        while(hantei){
        	if(turn == 'a'){
        		if(a.length() == 0 ){
        			ans = 'A';
        			hantei = false;
        			break;
        		}
        		
        		turn = a.charAt(0);
        		a.deleteCharAt(0);
        	}

        	if(turn == 'b'){
        		if(b.length() == 0 ){
        			ans = 'B';
        			hantei = false;
        			break;
        		}

        		turn = b.charAt(0);
        		b.deleteCharAt(0);
        	}

        	if(turn == 'c'){
        		if(c.length() == 0 ){
        			ans = 'C';
        			hantei = false;
        			break;
        		}

        		turn = c.charAt(0);
        		c.deleteCharAt(0);
        	}

        }

        System.out.println(ans);
    }
}
/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