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);
		int Along = SA.length();
		int Blong = SB.length();
		int Clong = SC.length();
		String ans = "X";
		
		while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
	}
} 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);
		int Along = SA.length();
		int Blong = SB.length();
		int Clong = SC.length();
		String ans = "X";
		
		while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
	}
} 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);
		int Along = SA.length();
		int Blong = SB.length();
		int Clong = SC.length();
		String ans = "X";
		
		while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
	} 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);
		int Along = SA.length();
		int Blong = SB.length();
		int Clong = SC.length();
		String ans = "X";
		
		while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
	} 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 int Along = SA.length(); Along SA.length() SA.length SA int Blong = SB.length(); Blong SB.length() SB.length SB int Clong = SC.length(); Clong SC.length() SC.length SC String ans = "X"; ans "X" while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		} ans.equals("X") ans.equals ans "X" {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		} if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			} input.equals("a") input.equals input "a" {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			} if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				} Along != 0 Along 0 {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				} input = SA.substring(0,1) input SA.substring(0,1) SA.substring SA 0 1 SA = SA.substring(1, Along) SA SA.substring(1, Along) SA.substring SA 1 Along Along-- Along continue; {
					ans = "A";
				} ans = "A" ans "A" if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			} input.equals("b") input.equals input "b" {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			} if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				} Blong != 0 Blong 0 {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				} input = SB.substring(0,1) input SB.substring(0,1) SB.substring SB 0 1 SB = SB.substring(1, Blong) SB SB.substring(1, Blong) SB.substring SB 1 Blong Blong-- Blong continue; {
					ans = "B";
				} ans = "B" ans "B" { 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			} if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				} Clong != 0 Clong 0 {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				} input = SC.substring(0,1) input SC.substring(0,1) SC.substring SC 0 1 SC = SC.substring(1, Clong) SC SC.substring(1, Clong) SC.substring SC 1 Clong Clong-- Clong continue; {
					ans = "C";
				} ans = "C" ans "C" System.out.print(ans) System.out.print System.out System System.out ans keyboard.close() keyboard.close keyboard String[] args args 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);
		int Along = SA.length();
		int Blong = SB.length();
		int Clong = SC.length();
		String ans = "X";
		
		while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
	}
} 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);
		int Along = SA.length();
		int Blong = SB.length();
		int Clong = SC.length();
		String ans = "X";
		
		while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
	}
} 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);
		int Along = SA.length();
		int Blong = SB.length();
		int Clong = SC.length();
		String ans = "X";
		
		while(ans.equals("X")) {
			if(input.equals("a")) {
				if(Along != 0) {
					input = SA.substring(0,1);
					SA = SA.substring(1, Along);
					Along--;
					continue;
				}else {
					ans = "A";
				}
			}else if(input.equals("b")) {
				if(Blong != 0) {
					input = SB.substring(0,1);
					SB = SB.substring(1, Blong);
					Blong--;
					continue;
				}else {
					ans = "B";
				}
			}else{ 	//(input.equals("c")) 
				if(Clong != 0) {
					input = SC.substring(0,1);
					SC = SC.substring(1, Clong);
					Clong--;
					continue;
				}else {
					ans = "C";
				}
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
	}
}
