import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(), b = sc.next(), c = sc.next();
		char t = 'a';
		int ac = 0, bc = 0, cc = 0;		
		while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		}
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(), b = sc.next(), c = sc.next();
		char t = 'a';
		int ac = 0, bc = 0, cc = 0;		
		while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(), b = sc.next(), c = sc.next();
		char t = 'a';
		int ac = 0, bc = 0, cc = 0;		
		while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(), b = sc.next(), c = sc.next();
		char t = 'a';
		int ac = 0, bc = 0, cc = 0;		
		while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String a = sc.next() a sc.next() sc.next sc b = sc.next() b sc.next() sc.next sc c = sc.next(); c sc.next() sc.next sc char t = 'a'; t 'a' int ac = 0 ac 0 bc = 0 bc 0 cc = 0; cc 0 while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		} true {
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		} if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			} t == 'a' t 'a' {
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			} if(ac == a.length()){
					System.out.println("A");
					break;
				} ac == a.length() ac a.length() a.length a {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; t = a.charAt(ac) t a.charAt(ac) a.charAt a ac ac++ ac if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			} t == 'b' t 'b' {
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			} if(bc == b.length()){
					System.out.println("B");
					break;
				} bc == b.length() bc b.length() b.length b {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; t = b.charAt(bc) t b.charAt(bc) b.charAt b bc bc++ bc if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			} t == 'c' t 'c' {
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			} if(cc == c.length()){
					System.out.println("C");
					break;
				} cc == c.length() cc c.length() c.length c {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; t = c.charAt(cc) t c.charAt(cc) c.charAt c cc cc++ cc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(), b = sc.next(), c = sc.next();
		char t = 'a';
		int ac = 0, bc = 0, cc = 0;		
		while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(), b = sc.next(), c = sc.next();
		char t = 'a';
		int ac = 0, bc = 0, cc = 0;		
		while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		}
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(), b = sc.next(), c = sc.next();
		char t = 'a';
		int ac = 0, bc = 0, cc = 0;		
		while(true){
			if(t == 'a'){
				if(ac == a.length()){
					System.out.println("A");
					break;
				}
				t = a.charAt(ac);
				ac++;
			}else if(t == 'b'){
				if(bc == b.length()){
					System.out.println("B");
					break;
				}
				t = b.charAt(bc);
				bc++;
			}else if(t == 'c'){
				if(cc == c.length()){
					System.out.println("C");
					break;
				}
				t = c.charAt(cc);
				cc++;
			}
		}
	}
}