import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char next = 'a';
		while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		}
	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char next = 'a';
		while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		}
	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char next = 'a';
		while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		}
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char next = 'a';
		while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		}
	} 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 char next = 'a'; next 'a' while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		} true {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		} if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			} next == 'a' next 'a' {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			} if(a.length()==0) {
					System.out.println("A");
					break;
				} a.length()==0 a.length() a.length a 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; next = a.charAt(0) next a.charAt(0) a.charAt a 0 a = a.substring(1) a a.substring(1) a.substring a 1 if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			} next == 'b' next 'b' {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			} if(b.length()==0) {
					System.out.println("B");
					break;
				} b.length()==0 b.length() b.length b 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; next = b.charAt(0) next b.charAt(0) b.charAt b 0 b = b.substring(1) b b.substring(1) b.substring b 1 {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			} if(c.length()==0) {
					System.out.println("C");
					break;
				} c.length()==0 c.length() c.length c 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; next = c.charAt(0) next c.charAt(0) c.charAt c 0 c = c.substring(1) c c.substring(1) c.substring c 1 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char next = 'a';
		while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		}
	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char next = 'a';
		while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		}
	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		char next = 'a';
		while(true) {
			if(next == 'a') {
				if(a.length()==0) {
					System.out.println("A");
					break;
				}
				next = a.charAt(0);
				a = a.substring(1);
			}else if(next == 'b') {
				if(b.length()==0) {
					System.out.println("B");
					break;
				}
				next = b.charAt(0);
				b = b.substring(1);
			}else {
				if(c.length()==0) {
					System.out.println("C");
					break;
				}
				next = c.charAt(0);
				c = c.substring(1);
			}
	//		System.out.println(next);
		}
	}

}