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();
		char t = A[0];
		int a = 1; int b = 0; int c = 0;
		String res = "";
		while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		}
		System.out.println(res);
	}
} 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();
		char t = A[0];
		int a = 1; int b = 0; int c = 0;
		String res = "";
		while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		}
		System.out.println(res);
	}
} 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();
		char t = A[0];
		int a = 1; int b = 0; int c = 0;
		String res = "";
		while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		}
		System.out.println(res);
	} main {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		char t = A[0];
		int a = 1; int b = 0; int c = 0;
		String res = "";
		while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		}
		System.out.println(res);
	} 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 char t = A[0]; t A[0] A 0 int a = 1; a 1 int b = 0; b 0 int c = 0; c 0 String res = ""; res "" while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		} true {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		} if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			} t == 'a' t 'a' {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			} if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				} a == A.length a A.length A A.length {
					res = "A";
					break;
				} res = "A" res "A" break; {
					t = A[a];
					a++;
				} t = A[a] t A[a] A a a++ a if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			} t == 'b' t 'b' {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			} if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				} b == B.length b B.length B B.length {
					res = "B";
					break;
				} res = "B" res "B" break; {
					t = B[b];
					b++;
				} t = B[b] t B[b] B b b++ b if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			} t == 'c' t 'c' {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			} if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				} c == C.length c C.length C C.length {
					res = "C";
					break;
				} res = "C" res "C" break; {
					t = C[c];
					c++;
				} t = C[c] t C[c] C c c++ c System.out.println(res) System.out.println System.out System System.out res String[] args args 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();
		char t = A[0];
		int a = 1; int b = 0; int c = 0;
		String res = "";
		while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		}
		System.out.println(res);
	}
} 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();
		char t = A[0];
		int a = 1; int b = 0; int c = 0;
		String res = "";
		while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		}
		System.out.println(res);
	}
} 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();
		char t = A[0];
		int a = 1; int b = 0; int c = 0;
		String res = "";
		while(true) {
			if (t == 'a') {
				if (a == A.length) {
					res = "A";
					break;
				} else {
					t = A[a];
					a++;
				}
			}else if (t == 'b') {
				if (b == B.length) {
					res = "B";
					break;
				} else {
					t = B[b];
					b++;
				}
			}else if (t == 'c') {
				if (c == C.length) {
					res = "C";
					break;
				} else {
					t = C[c];
					c++;
				}
			}
		}
		System.out.println(res);
	}
}
