import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int a_count = 0;
		int b_count = 0;
		int c_count = 0;
		char tern = 'a';
		while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		}

	}

	public static boolean checkWin(char[] ary,int count) {
		if(ary.length == count) return true;
		return false;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int a_count = 0;
		int b_count = 0;
		int c_count = 0;
		char tern = 'a';
		while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		}

	}

	public static boolean checkWin(char[] ary,int count) {
		if(ary.length == count) return true;
		return false;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int a_count = 0;
		int b_count = 0;
		int c_count = 0;
		char tern = 'a';
		while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		}

	} main {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int a_count = 0;
		int b_count = 0;
		int c_count = 0;
		char tern = 'a';
		while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] a = sc.next().toCharArray(); a sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] b = sc.next().toCharArray(); b sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] c = sc.next().toCharArray(); c sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int a_count = 0; a_count 0 int b_count = 0; b_count 0 int c_count = 0; c_count 0 char tern = 'a'; tern 'a' while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		} true {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		} if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			} tern == 'a' tern 'a' {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			} if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				} checkWin(a, a_count) checkWin a a_count {
					System.out.println('A');
					break;
				} System.out.println('A') System.out.println System.out System System.out 'A' break; tern = a[a_count] tern a[a_count] a a_count a_count++ a_count if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			} tern == 'b' tern 'b' {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			} if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				} checkWin(b, b_count) checkWin b b_count {
					System.out.println('B');
					break;
				} System.out.println('B') System.out.println System.out System System.out 'B' break; tern = b[b_count] tern b[b_count] b b_count b_count++ b_count if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			} tern == 'c' tern 'c' {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			} if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				} checkWin(c, c_count) checkWin c c_count {
					System.out.println('C');
					break;
				} System.out.println('C') System.out.println System.out System System.out 'C' break; tern = c[c_count] tern c[c_count] c c_count c_count++ c_count String[] args args public static boolean checkWin(char[] ary,int count) {
		if(ary.length == count) return true;
		return false;
	} checkWin {
		if(ary.length == count) return true;
		return false;
	} if(ary.length == count) return true; ary.length == count ary.length ary ary.length count return true; true return false; false char[] ary ary int count count public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int a_count = 0;
		int b_count = 0;
		int c_count = 0;
		char tern = 'a';
		while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		}

	}

	public static boolean checkWin(char[] ary,int count) {
		if(ary.length == count) return true;
		return false;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int a_count = 0;
		int b_count = 0;
		int c_count = 0;
		char tern = 'a';
		while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		}

	}

	public static boolean checkWin(char[] ary,int count) {
		if(ary.length == count) return true;
		return false;
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int a_count = 0;
		int b_count = 0;
		int c_count = 0;
		char tern = 'a';
		while(true) {
			if(tern == 'a') {
				if(checkWin(a, a_count)){
					System.out.println('A');
					break;
				}
				tern = a[a_count];
				a_count++;
			}
			if(tern == 'b') {
				if(checkWin(b, b_count)){
					System.out.println('B');
					break;
				}
				tern = b[b_count];
				b_count++;
			}
			if(tern == 'c') {
				if(checkWin(c, c_count)){
					System.out.println('C');
					break;
				}
				tern = c[c_count];
				c_count++;
			}
		}

	}

	public static boolean checkWin(char[] ary,int count) {
		if(ary.length == count) return true;
		return false;
	}
}