import java.util.*;
public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	}

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

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	}

} Main private static Scanner sc; sc public static void main(String[] args) {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	} main {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	} sc = new Scanner(System.in) sc new Scanner(System.in) String sa = sc.next(); sa sc.next() sc.next sc String sb = sc.next(); sb sc.next() sc.next sc String scc = sc.next(); scc sc.next() sc.next sc int a=0 a 0 b=0 b 0 c=0 c 0 turn=0; turn 0 for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		} ; {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		} {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		} if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			} turn==0 turn 0 {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			} if(sa.length()==a){
					System.out.println('A');
					break;
				} sa.length()==a sa.length() sa.length sa a {
					System.out.println('A');
					break;
				} System.out.println('A') System.out.println System.out System System.out 'A' break; turn =sa.charAt(a)-'a' turn sa.charAt(a)-'a' sa.charAt(a) sa.charAt sa a 'a' a++ a if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			} turn==1 turn 1 {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			} if(sb.length()==b) {
					System.out.println('B');
					break;
				} sb.length()==b sb.length() sb.length sb b {
					System.out.println('B');
					break;
				} System.out.println('B') System.out.println System.out System System.out 'B' break; turn =sb.charAt(b)-'a' turn sb.charAt(b)-'a' sb.charAt(b) sb.charAt sb b 'a' b++ b {
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			} if(scc.length()==c) {
					System.out.println('C');
					break;
				} scc.length()==c scc.length() scc.length scc c {
					System.out.println('C');
					break;
				} System.out.println('C') System.out.println System.out System System.out 'C' break; turn = scc.charAt(c)-'a' turn scc.charAt(c)-'a' scc.charAt(c) scc.charAt scc c 'a' c++ c String[] args args public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	}

} public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	}

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

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	}

}