import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String SA = keyboard.nextLine();	
		String SB = keyboard.nextLine();	
		String SC = keyboard.nextLine();	
		
		String input = SA.substring(0,1);

		keyboard.close();	
              System.out.print(solve(SA,SB,SC,input));

	}


public static String solve(String A, String B, String C, String input2) {
		String output ;

			if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			}
		}
} import java.util.Arrays; Arrays java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String SA = keyboard.nextLine();	
		String SB = keyboard.nextLine();	
		String SC = keyboard.nextLine();	
		
		String input = SA.substring(0,1);

		keyboard.close();	
              System.out.print(solve(SA,SB,SC,input));

	}


public static String solve(String A, String B, String C, String input2) {
		String output ;

			if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			}
		}
} Main public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String SA = keyboard.nextLine();	
		String SB = keyboard.nextLine();	
		String SC = keyboard.nextLine();	
		
		String input = SA.substring(0,1);

		keyboard.close();	
              System.out.print(solve(SA,SB,SC,input));

	} main {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String SA = keyboard.nextLine();	
		String SB = keyboard.nextLine();	
		String SC = keyboard.nextLine();	
		
		String input = SA.substring(0,1);

		keyboard.close();	
              System.out.print(solve(SA,SB,SC,input));

	} Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) String SA = keyboard.nextLine(); SA keyboard.nextLine() keyboard.nextLine keyboard String SB = keyboard.nextLine(); SB keyboard.nextLine() keyboard.nextLine keyboard String SC = keyboard.nextLine(); SC keyboard.nextLine() keyboard.nextLine keyboard String input = SA.substring(0,1); input SA.substring(0,1) SA.substring SA 0 1 keyboard.close() keyboard.close keyboard System.out.print(solve(SA,SB,SC,input)) System.out.print System.out System System.out solve(SA,SB,SC,input) solve SA SB SC input String[] args args public static String solve(String A, String B, String C, String input2) {
		String output ;

			if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			}
		} solve {
		String output ;

			if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			}
		} String output ; output if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			} input2.equals("a") input2.equals input2 "a" {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			} if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				} A.length() != 0 A.length() A.length A 0 {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				} output = A.substring(0,1) output A.substring(0,1) A.substring A 0 1 return solve(A.substring(1), B, C, output); solve(A.substring(1), B, C, output) solve A.substring(1) A.substring A 1 B C output {
					return "A";
				} return "A"; "A" if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			} input2.equals("b") input2.equals input2 "b" {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			} if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				} B.length() != 0 B.length() B.length B 0 {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				} output = B.substring(0,1) output B.substring(0,1) B.substring B 0 1 return solve(A, B.substring(1), C, output); solve(A, B.substring(1), C, output) solve A B.substring(1) B.substring B 1 C output {
					return "B";
				} return "B"; "B" { 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			} if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				} C.length() != 0 C.length() C.length C 0 {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				} output = C.substring(0,1) output C.substring(0,1) C.substring C 0 1 return solve(A, B, C.substring(1), output); solve(A, B, C.substring(1), output) solve A B C.substring(1) C.substring C 1 output {
					return "C";
				} return "C"; "C" String A A String B B String C C String input2 input2 public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String SA = keyboard.nextLine();	
		String SB = keyboard.nextLine();	
		String SC = keyboard.nextLine();	
		
		String input = SA.substring(0,1);

		keyboard.close();	
              System.out.print(solve(SA,SB,SC,input));

	}


public static String solve(String A, String B, String C, String input2) {
		String output ;

			if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			}
		}
} public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String SA = keyboard.nextLine();	
		String SB = keyboard.nextLine();	
		String SC = keyboard.nextLine();	
		
		String input = SA.substring(0,1);

		keyboard.close();	
              System.out.print(solve(SA,SB,SC,input));

	}


public static String solve(String A, String B, String C, String input2) {
		String output ;

			if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			}
		}
} Main
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String SA = keyboard.nextLine();	
		String SB = keyboard.nextLine();	
		String SC = keyboard.nextLine();	
		
		String input = SA.substring(0,1);

		keyboard.close();	
              System.out.print(solve(SA,SB,SC,input));

	}


public static String solve(String A, String B, String C, String input2) {
		String output ;

			if(input2.equals("a")) {
				if(A.length() != 0) {
					output = A.substring(0,1);
					return solve(A.substring(1), B, C, output);
				}else {
					return "A";
				}
			}else if(input2.equals("b")) {
				if(B.length() != 0) {
					output = B.substring(0,1);
					return solve(A, B.substring(1), C, output);
				}else {
					return "B";
				}
			}else{ 	//(input2.equals("c")) 
				if(C.length() != 0) {
					output = C.substring(0,1);
					return solve(A, B, C.substring(1), output);
				}else {
					return "C";
				}
			}
		}
}
