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;
				}
			}
		}
	}
} import java.util.Scanner; Scanner java.util 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;
				}
			}
		}
	}
} 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;
				}
			}
		}
	} main {
		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;
				}
			}
		}
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) String A=scan.next(); A scan.next() scan.next scan String B=scan.next(); B scan.next() scan.next scan String C=scan.next(); C scan.next() scan.next scan int ac=0 ac 0 bc=0 bc 0 cc=0 cc 0 c=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;
				}
			}
		} ; {
			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;
				}
			}
		} {
			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;
				}
			}
		} 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;
				}
			} c==0 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;
				}
			} ac++ ac if(ac==A.length()+1) {
					System.out.println("A");
					break;
				} ac==A.length()+1 ac A.length()+1 A.length() A.length A 1 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; switch(A.charAt(ac-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				} A.charAt(ac-1) A.charAt A ac-1 ac 1 case 'a': 'a' case 'a': c=0 c 0 break; case 'b': 'b' case 'b': c=1 c 1 break; case 'c': 'c' case 'c': c=2 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;
				}
			} c==1 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;
				}
			} bc++ bc if(bc==B.length()+1) {
					System.out.println("B");
					break;
				} bc==B.length()+1 bc B.length()+1 B.length() B.length B 1 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; switch(B.charAt(bc-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				} B.charAt(bc-1) B.charAt B bc-1 bc 1 case 'a': 'a' case 'a': c=0 c 0 break; case 'b': 'b' case 'b': c=1 c 1 break; case 'c': 'c' case 'c': c=2 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;
				}
			} c==2 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;
				}
			} cc++ cc if(cc==C.length()+1) {
					System.out.println("C");
					break;
				} cc==C.length()+1 cc C.length()+1 C.length() C.length C 1 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; switch(C.charAt(cc-1)) {
				case 'a':c=0;break;
				case 'b':c=1;break;
				case 'c':c=2;break;
				} C.charAt(cc-1) C.charAt C cc-1 cc 1 case 'a': 'a' case 'a': c=0 c 0 break; case 'b': 'b' case 'b': c=1 c 1 break; case 'c': 'c' case 'c': c=2 c 2 break; String[] args args 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;
				}
			}
		}
	}
} 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;
				}
			}
		}
	}
} Main
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;
				}
			}
		}
	}
}
