import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	} main {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) String a=sc.next() a sc.next() sc.next sc b=sc.next() b sc.next() sc.next sc c=sc.next(); c sc.next() sc.next sc String pre="a"; pre "a" for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		} ; {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		} {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		} if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			} pre.equals("a") pre.equals pre "a" {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			} if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				} a.length()==0 a.length() a.length a 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				} pre=a.charAt(0)+"" pre a.charAt(0)+"" a.charAt(0) a.charAt a 0 "" a=a.substring(1) a a.substring(1) a.substring a 1 if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			} pre.equals("b") pre.equals pre "b" {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			} if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				} b.length()==0 b.length() b.length b 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				} pre=b.charAt(0)+"" pre b.charAt(0)+"" b.charAt(0) b.charAt b 0 "" b=b.substring(1) b b.substring(1) b.substring b 1 if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			} pre.equals("c") pre.equals pre "c" {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			} if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				} c.length()==0 c.length() c.length c 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				} pre=c.charAt(0)+"" pre c.charAt(0)+"" c.charAt(0) c.charAt c 0 "" c=c.substring(1) c c.substring(1) c.substring c 1 sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	}
}