import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String sa = scanner.next();
		String sb = scanner.next();
		String sc = scanner.next();
		scanner.close();
		
		int aidx = 0, bidx = 0, cidx = 0;
		char next = 'a';
		char ans = 0;
		while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String sa = scanner.next();
		String sb = scanner.next();
		String sc = scanner.next();
		scanner.close();
		
		int aidx = 0, bidx = 0, cidx = 0;
		char next = 'a';
		char ans = 0;
		while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String sa = scanner.next();
		String sb = scanner.next();
		String sc = scanner.next();
		scanner.close();
		
		int aidx = 0, bidx = 0, cidx = 0;
		char next = 'a';
		char ans = 0;
		while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		}
		System.out.println(ans);
	} main {
		Scanner scanner = new Scanner(System.in);
		String sa = scanner.next();
		String sb = scanner.next();
		String sc = scanner.next();
		scanner.close();
		
		int aidx = 0, bidx = 0, cidx = 0;
		char next = 'a';
		char ans = 0;
		while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		}
		System.out.println(ans);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String sa = scanner.next(); sa scanner.next() scanner.next scanner String sb = scanner.next(); sb scanner.next() scanner.next scanner String sc = scanner.next(); sc scanner.next() scanner.next scanner scanner.close() scanner.close scanner int aidx = 0 aidx 0 bidx = 0 bidx 0 cidx = 0; cidx 0 char next = 'a'; next 'a' char ans = 0; ans 0 while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		} ans == 0 ans 0 {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		} switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			} next case 'a': 'a' case 'a': if(aidx == sa.length()) {
					ans = 'A';
					break;
				} aidx == sa.length() aidx sa.length() sa.length sa {
					ans = 'A';
					break;
				} ans = 'A' ans 'A' break; next = sa.charAt(aidx) next sa.charAt(aidx) sa.charAt sa aidx aidx++ aidx break; case 'b': 'b' case 'b': if(bidx == sb.length()) {
					ans = 'B';
					break;
				} bidx == sb.length() bidx sb.length() sb.length sb {
					ans = 'B';
					break;
				} ans = 'B' ans 'B' break; next = sb.charAt(bidx) next sb.charAt(bidx) sb.charAt sb bidx bidx++ bidx break; case 'c': 'c' case 'c': if(cidx == sc.length()) {
					ans = 'C';
					break;
				} cidx == sc.length() cidx sc.length() sc.length sc {
					ans = 'C';
					break;
				} ans = 'C' ans 'C' break; next = sc.charAt(cidx) next sc.charAt(cidx) sc.charAt sc cidx cidx++ cidx break; 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 scanner = new Scanner(System.in);
		String sa = scanner.next();
		String sb = scanner.next();
		String sc = scanner.next();
		scanner.close();
		
		int aidx = 0, bidx = 0, cidx = 0;
		char next = 'a';
		char ans = 0;
		while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		}
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String sa = scanner.next();
		String sb = scanner.next();
		String sc = scanner.next();
		scanner.close();
		
		int aidx = 0, bidx = 0, cidx = 0;
		char next = 'a';
		char ans = 0;
		while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String sa = scanner.next();
		String sb = scanner.next();
		String sc = scanner.next();
		scanner.close();
		
		int aidx = 0, bidx = 0, cidx = 0;
		char next = 'a';
		char ans = 0;
		while(ans == 0) {
			switch(next) {
			case 'a':
				if(aidx == sa.length()) {
					ans = 'A';
					break;
				}
				next = sa.charAt(aidx);
				aidx++;
				break;
			case 'b':
				if(bidx == sb.length()) {
					ans = 'B';
					break;
				}
				next = sb.charAt(bidx);
				bidx++;
				break;
			case 'c':
				if(cidx == sc.length()) {
					ans = 'C';
					break;
				}
				next = sc.charAt(cidx);
				cidx++;
				break;
			}
		}
		System.out.println(ans);
	}
}
