import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    }
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    } main {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String A = sc.next(); A sc.next() sc.next sc String B = sc.next(); B sc.next() sc.next sc String C = sc.next(); C sc.next() sc.next sc String next = A.substring(0, 1); next A.substring(0, 1) A.substring A 0 1 A = A.substring(1, A.length()) A A.substring(1, A.length()) A.substring A 1 A.length() A.length A for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		} ; {
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		} {
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		} if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			} next.equals("a") next.equals next "a" {
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			} if(A.isEmpty()){
					System.out.println("A");
					return;
				} A.isEmpty() A.isEmpty A {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; next = A.substring(0, 1) next A.substring(0, 1) A.substring A 0 1 A = A.substring(1, A.length()) A A.substring(1, A.length()) A.substring A 1 A.length() A.length A if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			} next.equals("b") next.equals next "b" {
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			} if(B.isEmpty()){
					System.out.println("B");
					return;
				} B.isEmpty() B.isEmpty B {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; next = B.substring(0, 1) next B.substring(0, 1) B.substring B 0 1 B = B.substring(1, B.length()) B B.substring(1, B.length()) B.substring B 1 B.length() B.length B {
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			} if(C.isEmpty()){
					System.out.println("C");
					return;
				} C.isEmpty() C.isEmpty C {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; next = C.substring(0, 1) next C.substring(0, 1) C.substring C 0 1 C = C.substring(1, C.length()) C C.substring(1, C.length()) C.substring C 1 C.length() C.length C String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    }
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    }
} Main
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    }
}
