import java.util.Scanner;

public class Main {
		public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		char[] c = scan.next().toCharArray();
		int A = 0;
		int B = 0;
		int C = 0;
		char x = a[0];
		String ans = "";
		while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
		public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		char[] c = scan.next().toCharArray();
		int A = 0;
		int B = 0;
		int C = 0;
		char x = a[0];
		String ans = "";
		while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		char[] c = scan.next().toCharArray();
		int A = 0;
		int B = 0;
		int C = 0;
		char x = a[0];
		String ans = "";
		while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		}
		System.out.println(ans);
	} main {
		Scanner scan = new Scanner(System.in);
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		char[] c = scan.next().toCharArray();
		int A = 0;
		int B = 0;
		int C = 0;
		char x = a[0];
		String ans = "";
		while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		}
		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) char[] a = scan.next().toCharArray(); a scan.next().toCharArray() scan.next().toCharArray scan.next() scan.next scan char[] b = scan.next().toCharArray(); b scan.next().toCharArray() scan.next().toCharArray scan.next() scan.next scan char[] c = scan.next().toCharArray(); c scan.next().toCharArray() scan.next().toCharArray scan.next() scan.next scan int A = 0; A 0 int B = 0; B 0 int C = 0; C 0 char x = a[0]; x a[0] a 0 String ans = ""; ans "" while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		} true {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		} if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			} x == 'a' x 'a' {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			} A++ A if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A]; A==a.length A a.length a a.length {
					ans = "A";
					break;
				} ans = "A" ans "A" break; x = a[A] x a[A] a A if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			} x == 'b' x 'b' {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			} if (B==b.length) {
					ans = "B";
					break;
				} B==b.length B b.length b b.length {
					ans = "B";
					break;
				} ans = "B" ans "B" break; x = b[B] x b[B] b B B++ B if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			} x == 'c' x 'c' {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			} if (C==c.length) {
					ans = "C";
					break;
				} C==c.length C c.length c c.length {
					ans = "C";
					break;
				} ans = "C" ans "C" break; x = c[C] x c[C] c C C++ C System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
		public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		char[] c = scan.next().toCharArray();
		int A = 0;
		int B = 0;
		int C = 0;
		char x = a[0];
		String ans = "";
		while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		}
		System.out.println(ans);
	}
} public class Main {
		public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		char[] c = scan.next().toCharArray();
		int A = 0;
		int B = 0;
		int C = 0;
		char x = a[0];
		String ans = "";
		while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
		public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		char[] c = scan.next().toCharArray();
		int A = 0;
		int B = 0;
		int C = 0;
		char x = a[0];
		String ans = "";
		while (true) {
			if (x == 'a') {
				A++;
				if (A==a.length) {
					ans = "A";
					break;
				} else
				x = a[A];
			}
			if (x == 'b') {
				if (B==b.length) {
					ans = "B";
					break;
				}
				x = b[B];
				B++;
			}
			if (x == 'c') {
				if (C==c.length) {
					ans = "C";
					break;
				}
				x = c[C];
				C++;
			}
		}
		System.out.println(ans);
	}
}
