import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		char[] sa = a.toCharArray();
		char[] sb = b.toCharArray();
		char[] sc = c.toCharArray();
		int countA = 0;
		int countB = 0;
		int countC =0;

		for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		char[] sa = a.toCharArray();
		char[] sb = b.toCharArray();
		char[] sc = c.toCharArray();
		int countA = 0;
		int countB = 0;
		int countC =0;

		for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

}
	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		char[] sa = a.toCharArray();
		char[] sb = b.toCharArray();
		char[] sc = c.toCharArray();
		int countA = 0;
		int countB = 0;
		int countC =0;

		for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

}
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		char[] sa = a.toCharArray();
		char[] sb = b.toCharArray();
		char[] sc = c.toCharArray();
		int countA = 0;
		int countB = 0;
		int countC =0;

		for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String a = scan.next(); a scan.next() scan.next scan String b = scan.next(); b scan.next() scan.next scan String c = scan.next(); c scan.next() scan.next scan char[] sa = a.toCharArray(); sa a.toCharArray() a.toCharArray a char[] sb = b.toCharArray(); sb b.toCharArray() b.toCharArray b char[] sc = c.toCharArray(); sc c.toCharArray() c.toCharArray c int countA = 0; countA 0 int countB = 0; countB 0 int countC =0; countC 0 for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

} int i=0,m=-1,n=-1; int i=0 i 0 m=-1 m -1 1 n=-1; n -1 1 {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

} {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

} if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			} sa[i]=='a' sa[i] sa i 'a' {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			} sa[i]='x' sa[i] sa i 'x' i++ i if(i==sa.length) {
					System.out.println("A");
					break;
				} i==sa.length i sa.length sa sa.length {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			} sa[i]=='b' sa[i] sa i 'b' {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			} sa[i]='x' sa[i] sa i 'x' m++ m if(m==sb.length) {
					System.out.println("B");
					break;
				} m==sb.length m sb.length sb sb.length {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			} sa[i]=='c' sa[i] sa i 'c' {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			} sa[i]='x' sa[i] sa i 'x' n++ n if(n==sc.length) {
					System.out.println("C");
					break;
				} n==sc.length n sc.length sc sc.length {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				} m>=0 m 0 {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				} if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				} sb[m]=='a' sb[m] sb m 'a' {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				} sb[m]='x' sb[m] sb m 'x' i++ i if(i==sa.length) {
						System.out.println("A");
						break;
					} i==sa.length i sa.length sa sa.length {
						System.out.println("A");
						break;
					} System.out.println("A") System.out.println System.out System System.out "A" break; if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				} sb[m]=='b' sb[m] sb m 'b' {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				} sb[m]='x' sb[m] sb m 'x' m++ m if(m==sb.length) {
						System.out.println("B");
						break;
					} m==sb.length m sb.length sb sb.length {
						System.out.println("B");
						break;
					} System.out.println("B") System.out.println System.out System System.out "B" break; if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				} sb[m]=='c' sb[m] sb m 'c' {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				} sb[m]='x' sb[m] sb m 'x' n++ n if(n==sc.length) {
						System.out.println("C");
						break;
				} n==sc.length n sc.length sc sc.length {
						System.out.println("C");
						break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	} n>=0 n 0 {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	} if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		} sc[n]=='a' sc[n] sc n 'a' {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				} sc[n]='x' sc[n] sc n 'x' i++ i if(i==sa.length) {
						System.out.println("A");
						break;
					} i==sa.length i sa.length sa sa.length {
						System.out.println("A");
						break;
					} System.out.println("A") System.out.println System.out System System.out "A" break; if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		} sc[n]=='b' sc[n] sc n 'b' {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				} sc[n]='x' sc[n] sc n 'x' m++ m if(m==sb.length) {
						System.out.println("B");
						break;
					} m==sb.length m sb.length sb sb.length {
						System.out.println("B");
						break;
					} System.out.println("B") System.out.println System.out System System.out "B" break; if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		} sc[n]=='c' sc[n] sc n 'c' {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		} sc[n]='x' sc[n] sc n 'x' n++ n if(n==sc.length) {
						System.out.println("C");
						break;
			} n==sc.length n sc.length sc sc.length {
						System.out.println("C");
						break;
			} System.out.println("C") System.out.println System.out System System.out "C" break; String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		char[] sa = a.toCharArray();
		char[] sb = b.toCharArray();
		char[] sc = c.toCharArray();
		int countA = 0;
		int countB = 0;
		int countC =0;

		for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

}
	}
} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		char[] sa = a.toCharArray();
		char[] sb = b.toCharArray();
		char[] sc = c.toCharArray();
		int countA = 0;
		int countB = 0;
		int countC =0;

		for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		char[] sa = a.toCharArray();
		char[] sb = b.toCharArray();
		char[] sc = c.toCharArray();
		int countA = 0;
		int countB = 0;
		int countC =0;

		for(int i=0,m=-1,n=-1;;) {
			if(sa[i]=='a') {

				sa[i]='x';
				i++;
				//System.out.println(1);
				if(i==sa.length) {
					System.out.println("A");
					break;
				}

			}else if(sa[i]=='b') {

				sa[i]='x';
			m++;
				//System.out.println(2);
				if(m==sb.length) {
					System.out.println("B");
					break;
				}
			}else if(sa[i]=='c') {

				sa[i]='x';
				n++;
				//System.out.println(3);
				if(n==sc.length) {
					System.out.println("C");
					break;
				}
			}

				if(m>=0) {
				if(sb[m]=='a') {

					sb[m]='x';
					i++;
					//System.out.println(4);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sb[m]=='b') {

					sb[m]='x';
					m++;
					//System.out.println(5);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sb[m]=='c') {

					sb[m]='x';
					n++;
					//System.out.println(6);
					if(n==sc.length) {
						System.out.println("C");
						break;
				}
				}
				}
					if(n>=0) {
					if(sc[n]=='a') {

					sc[n]='x';
					i++;
					//System.out.println(7);
					if(i==sa.length) {
						System.out.println("A");
						break;
					}

				}else if(sc[n]=='b') {

					sc[n]='x';
					m++;
					//System.out.println(8);
					if(m==sb.length) {
						System.out.println("B");
						break;
					}
				}else if(sc[n]=='c') {

					sc[n]='x';
					n++;
					//System.out.println(9);
					if(n==sc.length) {
						System.out.println("C");
						break;
			}
		}

	}

}
	}
}
