import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

	} main {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

	} 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 sc.close() sc.close sc int s = 0; s 0 while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		} true {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		} if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			} s == 0 s 0 {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			} if (A.length() == 0) {
					System.out.println("A");
					return;
				} A.length() == 0 A.length() A.length A 0 {
					System.out.println("A");
					return;
				} System.out.println("A") System.out.println System.out System System.out "A" return; if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				} A.charAt(0) == 'a' A.charAt(0) A.charAt A 0 'a' {
					s = 0;
				} s = 0 s 0 if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				} A.charAt(0) == 'b' A.charAt(0) A.charAt A 0 'b' {
					s = 1;
				} s = 1 s 1 if(A.charAt(0) == 'c') {
					s = 2;
				} A.charAt(0) == 'c' A.charAt(0) A.charAt A 0 'c' {
					s = 2;
				} s = 2 s 2 A = A.substring(1, A.length()) A A.substring(1, A.length()) A.substring A 1 A.length() A.length A if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			} s == 1 s 1 {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			} if (B.length() == 0) {
					System.out.println("B");
					return;
				} B.length() == 0 B.length() B.length B 0 {
					System.out.println("B");
					return;
				} System.out.println("B") System.out.println System.out System System.out "B" return; if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				} B.charAt(0) == 'a' B.charAt(0) B.charAt B 0 'a' {
					s = 0;
				} s = 0 s 0 if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				} B.charAt(0) == 'b' B.charAt(0) B.charAt B 0 'b' {
					s = 1;
				} s = 1 s 1 if(B.charAt(0) == 'c') {
					s = 2;
				} B.charAt(0) == 'c' B.charAt(0) B.charAt B 0 'c' {
					s = 2;
				} s = 2 s 2 B = B.substring(1, B.length()) B B.substring(1, B.length()) B.substring B 1 B.length() B.length B if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			} s == 2 s 2 {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			} if (C.length() == 0) {
					System.out.println("C");
					return;
				} C.length() == 0 C.length() C.length C 0 {
					System.out.println("C");
					return;
				} System.out.println("C") System.out.println System.out System System.out "C" return; if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				} C.charAt(0) == 'a' C.charAt(0) C.charAt C 0 'a' {
					s = 0;
				} s = 0 s 0 if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				} C.charAt(0) == 'b' C.charAt(0) C.charAt C 0 'b' {
					s = 1;
				} s = 1 s 1 if(C.charAt(0) == 'c') {
					s = 2;
				} C.charAt(0) == 'c' C.charAt(0) C.charAt C 0 'c' {
					s = 2;
				} s = 2 s 2 C = C.substring(1, C.length()) C C.substring(1, C.length()) C.substring C 1 C.length() C.length C String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

	}
}