import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String A = scan.nextLine(); A scan.nextLine() scan.nextLine scan String B = scan.nextLine(); B scan.nextLine() scan.nextLine scan String C = scan.nextLine(); C scan.nextLine() scan.nextLine scan List<String> AList = new ArrayList<String>(); AList new ArrayList<String>() List<String> BList = new ArrayList<String>(); BList new ArrayList<String>() List<String> CList = new ArrayList<String>(); CList new ArrayList<String>() String tmp = ""; tmp "" for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		} int i = 0; int i = 0; i 0 i < A.length() i A.length() A.length A i++ i++ i {
			AList.add(A.substring(i, i + 1));
		} {
			AList.add(A.substring(i, i + 1));
		} AList.add(A.substring(i, i + 1)) AList.add AList A.substring(i, i + 1) A.substring A i i + 1 i 1 for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		} int i = 0; int i = 0; i 0 i < B.length() i B.length() B.length B i++ i++ i {
			BList.add(B.substring(i, i + 1));
		} {
			BList.add(B.substring(i, i + 1));
		} BList.add(B.substring(i, i + 1)) BList.add BList B.substring(i, i + 1) B.substring B i i + 1 i 1 for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		} int i = 0; int i = 0; i 0 i < C.length() i C.length() C.length C i++ i++ i {
			CList.add(C.substring(i, i + 1));
		} {
			CList.add(C.substring(i, i + 1));
		} CList.add(C.substring(i, i + 1)) CList.add CList C.substring(i, i + 1) C.substring C i i + 1 i 1 if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		} AList.size() != 0 AList.size() AList.size AList 0 {
			tmp = AList.get(0);
			AList.remove(0);
		} tmp = AList.get(0) tmp AList.get(0) AList.get AList 0 AList.remove(0) AList.remove AList 0 while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		} true {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		} if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			} tmp.equals("a") tmp.equals tmp "a" {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				} AList.size() != 0 AList.size() AList.size AList 0 {
					tmp = AList.get(0);
					AList.remove(0);
				} tmp = AList.get(0) tmp AList.get(0) AList.get AList 0 AList.remove(0) AList.remove AList 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			} tmp.equals("b") tmp.equals tmp "b" {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				} BList.size() != 0 BList.size() BList.size BList 0 {
					tmp = BList.get(0);
					BList.remove(0);
				} tmp = BList.get(0) tmp BList.get(0) BList.get BList 0 BList.remove(0) BList.remove BList 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			} tmp.equals("c") tmp.equals tmp "c" {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			} if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				} CList.size() != 0 CList.size() CList.size CList 0 {
					tmp = CList.get(0);
					CList.remove(0);
				} tmp = CList.get(0) tmp CList.get(0) CList.get CList 0 CList.remove(0) CList.remove CList 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	}

} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String A = scan.nextLine();
		String B = scan.nextLine();
		String C = scan.nextLine();
		List<String> AList = new ArrayList<String>();
		List<String> BList = new ArrayList<String>();
		List<String> CList = new ArrayList<String>();
		String tmp = "";
		
		for(int i = 0; i < A.length(); i++) {
			AList.add(A.substring(i, i + 1));
		}
		for(int i = 0; i < B.length(); i++) {
			BList.add(B.substring(i, i + 1));
		}
		for(int i = 0; i < C.length(); i++) {
			CList.add(C.substring(i, i + 1));
		}
		
		if(AList.size() != 0) {
			tmp = AList.get(0);
			AList.remove(0);
		}
		
		while(true) {
			if(tmp.equals("a")) {
				if(AList.size() != 0) {
					tmp = AList.get(0);
					AList.remove(0);
				} else {
					System.out.println("A");
					break;
				}
			} else if(tmp.equals("b")) {
				if(BList.size() != 0) {
					tmp = BList.get(0);
					BList.remove(0);
				} else {
					System.out.println("B");
					break;
				}
			} else if(tmp.equals("c")) {
				if(CList.size() != 0) {
					tmp = CList.get(0);
					CList.remove(0);
				} else {
					System.out.println("C");
					break;
				}
			}
		}
		scan.close();
	}

}
