import java.util.Scanner;

public class Main{
	public static char abc_ans(String str_a, String str_b, String str_c){
		char[] a = str_a.toCharArray();
		char[] b = str_b.toCharArray();
		char[] c = str_c.toCharArray();

		int a_count = a.length;
		int b_count = b.length;
		int c_count = c.length;

		int a_number = 0;
		int b_number = 0;
		int c_number = 0;

		char x = a[a_number];
		while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		}
	}

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String str_a = scan.next();
		String str_b = scan.next();
		String str_c = scan.next();

		System.out.println(abc_ans(str_a,str_b,str_c));
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static char abc_ans(String str_a, String str_b, String str_c){
		char[] a = str_a.toCharArray();
		char[] b = str_b.toCharArray();
		char[] c = str_c.toCharArray();

		int a_count = a.length;
		int b_count = b.length;
		int c_count = c.length;

		int a_number = 0;
		int b_number = 0;
		int c_number = 0;

		char x = a[a_number];
		while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		}
	}

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String str_a = scan.next();
		String str_b = scan.next();
		String str_c = scan.next();

		System.out.println(abc_ans(str_a,str_b,str_c));
	}
} Main public static char abc_ans(String str_a, String str_b, String str_c){
		char[] a = str_a.toCharArray();
		char[] b = str_b.toCharArray();
		char[] c = str_c.toCharArray();

		int a_count = a.length;
		int b_count = b.length;
		int c_count = c.length;

		int a_number = 0;
		int b_number = 0;
		int c_number = 0;

		char x = a[a_number];
		while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		}
	} abc_ans {
		char[] a = str_a.toCharArray();
		char[] b = str_b.toCharArray();
		char[] c = str_c.toCharArray();

		int a_count = a.length;
		int b_count = b.length;
		int c_count = c.length;

		int a_number = 0;
		int b_number = 0;
		int c_number = 0;

		char x = a[a_number];
		while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		}
	} char[] a = str_a.toCharArray(); a str_a.toCharArray() str_a.toCharArray str_a char[] b = str_b.toCharArray(); b str_b.toCharArray() str_b.toCharArray str_b char[] c = str_c.toCharArray(); c str_c.toCharArray() str_c.toCharArray str_c int a_count = a.length; a_count a.length a a.length int b_count = b.length; b_count b.length b b.length int c_count = c.length; c_count c.length c c.length int a_number = 0; a_number 0 int b_number = 0; b_number 0 int c_number = 0; c_number 0 char x = a[a_number]; x a[a_number] a a_number while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		} true {
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		} switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			} x case 'a': 'a' case 'a': if(a_number >= a.length){
						return('A');
					} a_number >= a.length a_number a.length a a.length {
						return('A');
					} return('A'); ('A') x = a[a_number] x a[a_number] a a_number a_number ++ a_number break; case 'b': 'b' case 'b': if(b_number >= b.length){
						return('B');
					} b_number >= b.length b_number b.length b b.length {
						return('B');
					} return('B'); ('B') x = b[b_number] x b[b_number] b b_number b_number ++ b_number break; case 'c': 'c' case 'c': if(c_number >= c.length){
						return('C');
					} c_number >= c.length c_number c.length c c.length {
						return('C');
					} return('C'); ('C') x = c[c_number] x c[c_number] c c_number c_number ++ c_number break; String str_a str_a String str_b str_b String str_c str_c public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String str_a = scan.next();
		String str_b = scan.next();
		String str_c = scan.next();

		System.out.println(abc_ans(str_a,str_b,str_c));
	} main {
		Scanner scan = new Scanner(System.in);
		String str_a = scan.next();
		String str_b = scan.next();
		String str_c = scan.next();

		System.out.println(abc_ans(str_a,str_b,str_c));
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String str_a = scan.next(); str_a scan.next() scan.next scan String str_b = scan.next(); str_b scan.next() scan.next scan String str_c = scan.next(); str_c scan.next() scan.next scan System.out.println(abc_ans(str_a,str_b,str_c)) System.out.println System.out System System.out abc_ans(str_a,str_b,str_c) abc_ans str_a str_b str_c String args[] args public class Main{
	public static char abc_ans(String str_a, String str_b, String str_c){
		char[] a = str_a.toCharArray();
		char[] b = str_b.toCharArray();
		char[] c = str_c.toCharArray();

		int a_count = a.length;
		int b_count = b.length;
		int c_count = c.length;

		int a_number = 0;
		int b_number = 0;
		int c_number = 0;

		char x = a[a_number];
		while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		}
	}

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String str_a = scan.next();
		String str_b = scan.next();
		String str_c = scan.next();

		System.out.println(abc_ans(str_a,str_b,str_c));
	}
} public class Main{
	public static char abc_ans(String str_a, String str_b, String str_c){
		char[] a = str_a.toCharArray();
		char[] b = str_b.toCharArray();
		char[] c = str_c.toCharArray();

		int a_count = a.length;
		int b_count = b.length;
		int c_count = c.length;

		int a_number = 0;
		int b_number = 0;
		int c_number = 0;

		char x = a[a_number];
		while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		}
	}

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String str_a = scan.next();
		String str_b = scan.next();
		String str_c = scan.next();

		System.out.println(abc_ans(str_a,str_b,str_c));
	}
} Main
import java.util.Scanner;

public class Main{
	public static char abc_ans(String str_a, String str_b, String str_c){
		char[] a = str_a.toCharArray();
		char[] b = str_b.toCharArray();
		char[] c = str_c.toCharArray();

		int a_count = a.length;
		int b_count = b.length;
		int c_count = c.length;

		int a_number = 0;
		int b_number = 0;
		int c_number = 0;

		char x = a[a_number];
		while(true){
			switch (x){
				case 'a':
					if(a_number >= a.length){
						return('A');
					}
					x = a[a_number];

					a_number ++;
					break;
				case 'b':
					if(b_number >= b.length){
						return('B');
					}
					x = b[b_number];
					b_number ++;
					break;
				case 'c':
					if(c_number >= c.length){
						return('C');
					}
					x = c[c_number];
					c_number ++;
					break;
			}
		}
	}

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String str_a = scan.next();
		String str_b = scan.next();
		String str_c = scan.next();

		System.out.println(abc_ans(str_a,str_b,str_c));
	}
}
