import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		String A=scan.next();
		String B=scan.next();
		String C=scan.next();
		int ac=0,bc=0,cc=0,c=0;
		for(;;) {
			if(c==0) {
				ac++;
				if(ac==A.length()+1) {
					System.out.println("A");
					break;
				}
				switch(A.charAt(ac-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				}
			}if(c==1) {
				bc++;
				if(bc==B.length()+1) {
					System.out.println("B");
					break;
				}
				switch(B.charAt(bc-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				}
			}if(c==2) {
				cc++;
				if(cc==C.length()+1) {
					System.out.println("C");
					break;
				}
				switch(C.charAt(cc-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				}
			}
		}
	}
}

/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