import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	} main {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		} {
			sc.close();
		} sc.close() sc.close sc {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} String a = sc.nextLine(); a sc.nextLine() sc.nextLine sc String b = sc.nextLine(); b sc.nextLine() sc.nextLine sc String c = sc.nextLine(); c sc.nextLine() sc.nextLine sc StringBuilder sba = new StringBuilder(a); sba new StringBuilder(a) StringBuilder sbb = new StringBuilder(b); sbb new StringBuilder(b) StringBuilder sbc = new StringBuilder(c); sbc new StringBuilder(c) char next = sba.charAt(0); next sba.charAt(0) sba.charAt sba 0 sba.deleteCharAt(0) sba.deleteCharAt sba 0 while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			} true {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			} switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				} next case 'a' : 'a' case 'a' : if (sba.length() == 0) {
						System.out.println("A");
						return;
					} sba.length() == 0 sba.length() sba.length sba 0 {
						System.out.println("A");
						return;
					} System.out.println("A") System.out.println System.out System System.out "A" return; next = sba.charAt(0) next sba.charAt(0) sba.charAt sba 0 sba.deleteCharAt(0) sba.deleteCharAt sba 0 break; case 'b' : 'b' case 'b' : if (sbb.length() == 0) {
						System.out.println("B");
						return;
					} sbb.length() == 0 sbb.length() sbb.length sbb 0 {
						System.out.println("B");
						return;
					} System.out.println("B") System.out.println System.out System System.out "B" return; next = sbb.charAt(0) next sbb.charAt(0) sbb.charAt sbb 0 sbb.deleteCharAt(0) sbb.deleteCharAt sbb 0 break; case 'c' : 'c' case 'c' : if (sbc.length() == 0) {
						System.out.println("C");
						return;
					} sbc.length() == 0 sbc.length() sbc.length sbc 0 {
						System.out.println("C");
						return;
					} System.out.println("C") System.out.println System.out System System.out "C" return; next = sbc.charAt(0) next sbc.charAt(0) sbc.charAt sbc 0 sbc.deleteCharAt(0) sbc.deleteCharAt sbc 0 break; String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	}
}