import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		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);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		System.out.println(ans);

	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		System.out.println(ans);

	} main {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		System.out.println(ans);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String s1 = scan.next(); s1 scan.next() scan.next scan String s2 = scan.next(); s2 scan.next() scan.next scan String s3 = scan.next(); s3 scan.next() scan.next scan int len1 = s1.length(); len1 s1.length() s1.length s1 int len2 = s2.length(); len2 s2.length() s2.length s2 int len3 = s3.length(); len3 s3.length() s3.length s3 int counta = 0; counta 0 int countb = 0; countb 0 int countc = 0; countc 0 char temp = 'a'; temp 'a' char ans; ans while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		} true {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		} if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			} temp == 'a' temp 'a' {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} if (len1 <= counta) {
					ans = 'A';
					break;
				} len1 <= counta len1 counta {
					ans = 'A';
					break;
				} ans = 'A' ans 'A' break; temp = s1.charAt(counta) temp s1.charAt(counta) s1.charAt s1 counta counta++ counta if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			} temp == 'b' temp 'b' {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} if (len2 <= countb) {
					ans = 'B';
					break;
				} len2 <= countb len2 countb {
					ans = 'B';
					break;
				} ans = 'B' ans 'B' break; temp = s2.charAt(countb) temp s2.charAt(countb) s2.charAt s2 countb countb++ countb if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			} temp == 'c' temp 'c' {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			} if (len3 <= countc) {
					ans = 'C';
					break;
				} len3 <= countc len3 countc {
					ans = 'C';
					break;
				} ans = 'C' ans 'C' break; temp = s3.charAt(countc) temp s3.charAt(countc) s3.charAt s3 countc countc++ countc 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);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		System.out.println(ans);

	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		System.out.println(ans);

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		System.out.println(ans);

	}
}