import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String Sa=sc.next();
		String Sb=sc.next();
		String Sc=sc.next();
		StringBuilder SBa=new StringBuilder(Sa);
		StringBuilder SBb=new StringBuilder(Sb);
		StringBuilder SBc=new StringBuilder(Sc);
		String abc=SBa.substring(0, 1);
		SBa.delete(0, 1);
		
		while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String Sa=sc.next();
		String Sb=sc.next();
		String Sc=sc.next();
		StringBuilder SBa=new StringBuilder(Sa);
		StringBuilder SBb=new StringBuilder(Sb);
		StringBuilder SBc=new StringBuilder(Sc);
		String abc=SBa.substring(0, 1);
		SBa.delete(0, 1);
		
		while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String Sa=sc.next();
		String Sb=sc.next();
		String Sc=sc.next();
		StringBuilder SBa=new StringBuilder(Sa);
		StringBuilder SBb=new StringBuilder(Sb);
		StringBuilder SBc=new StringBuilder(Sc);
		String abc=SBa.substring(0, 1);
		SBa.delete(0, 1);
		
		while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		}
	} main {
		Scanner sc=new Scanner(System.in);
		String Sa=sc.next();
		String Sb=sc.next();
		String Sc=sc.next();
		StringBuilder SBa=new StringBuilder(Sa);
		StringBuilder SBb=new StringBuilder(Sb);
		StringBuilder SBc=new StringBuilder(Sc);
		String abc=SBa.substring(0, 1);
		SBa.delete(0, 1);
		
		while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		}
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) String Sa=sc.next(); Sa sc.next() sc.next sc String Sb=sc.next(); Sb sc.next() sc.next sc String Sc=sc.next(); Sc sc.next() sc.next sc StringBuilder SBa=new StringBuilder(Sa); SBa new StringBuilder(Sa) StringBuilder SBb=new StringBuilder(Sb); SBb new StringBuilder(Sb) StringBuilder SBc=new StringBuilder(Sc); SBc new StringBuilder(Sc) String abc=SBa.substring(0, 1); abc SBa.substring(0, 1) SBa.substring SBa 0 1 SBa.delete(0, 1) SBa.delete SBa 0 1 while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		} true {
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		} if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			} abc.equals("a") abc.equals abc "a" {
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			} if(SBa.length()==0){
					System.out.println("A");
					return;
				} SBa.length()==0 SBa.length() SBa.length SBa 0 {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; abc=SBa.substring(0,1) abc SBa.substring(0,1) SBa.substring SBa 0 1 SBa.delete(0,1) SBa.delete SBa 0 1 if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			} abc.equals("b") abc.equals abc "b" {
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			} if(SBb.length()==0){
					System.out.println("B");
					return;
				} SBb.length()==0 SBb.length() SBb.length SBb 0 {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; abc=SBb.substring(0,1) abc SBb.substring(0,1) SBb.substring SBb 0 1 SBb.delete(0, 1) SBb.delete SBb 0 1 if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			} abc.equals("c") abc.equals abc "c" {
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			} if(SBc.length()==0){
					System.out.println("C");
					return;
				} SBc.length()==0 SBc.length() SBc.length SBc 0 {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; abc=SBc.substring(0,1) abc SBc.substring(0,1) SBc.substring SBc 0 1 SBc.delete(0, 1) SBc.delete SBc 0 1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String Sa=sc.next();
		String Sb=sc.next();
		String Sc=sc.next();
		StringBuilder SBa=new StringBuilder(Sa);
		StringBuilder SBb=new StringBuilder(Sb);
		StringBuilder SBc=new StringBuilder(Sc);
		String abc=SBa.substring(0, 1);
		SBa.delete(0, 1);
		
		while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String Sa=sc.next();
		String Sb=sc.next();
		String Sc=sc.next();
		StringBuilder SBa=new StringBuilder(Sa);
		StringBuilder SBb=new StringBuilder(Sb);
		StringBuilder SBc=new StringBuilder(Sc);
		String abc=SBa.substring(0, 1);
		SBa.delete(0, 1);
		
		while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String Sa=sc.next();
		String Sb=sc.next();
		String Sc=sc.next();
		StringBuilder SBa=new StringBuilder(Sa);
		StringBuilder SBb=new StringBuilder(Sb);
		StringBuilder SBc=new StringBuilder(Sc);
		String abc=SBa.substring(0, 1);
		SBa.delete(0, 1);
		
		while(true){
			if(abc.equals("a")){
				if(SBa.length()==0){
					System.out.println("A");
					return;
				}
				abc=SBa.substring(0,1);
				SBa.delete(0,1);
			}else if(abc.equals("b")){
				if(SBb.length()==0){
					System.out.println("B");
					return;
				}
				abc=SBb.substring(0,1);
				SBb.delete(0, 1);
			}else if(abc.equals("c")){
				if(SBc.length()==0){
					System.out.println("C");
					return;
				}
				abc=SBc.substring(0,1);
				SBc.delete(0, 1);
			}
		}
	}
}
