import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	/* 入力 */
	String sa = scan.next();
	String sb = scan.next();
	String sc = scan.next();

	/* 前準備 */
	char turn = sa.charAt(0);
	sa = sa.substring(1,sa.length());

	while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	}
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	/* 入力 */
	String sa = scan.next();
	String sb = scan.next();
	String sc = scan.next();

	/* 前準備 */
	char turn = sa.charAt(0);
	sa = sa.substring(1,sa.length());

	while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	}
    }
} Main public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	/* 入力 */
	String sa = scan.next();
	String sb = scan.next();
	String sc = scan.next();

	/* 前準備 */
	char turn = sa.charAt(0);
	sa = sa.substring(1,sa.length());

	while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	}
    } main {
	Scanner scan = new Scanner(System.in);

	/* 入力 */
	String sa = scan.next();
	String sb = scan.next();
	String sc = scan.next();

	/* 前準備 */
	char turn = sa.charAt(0);
	sa = sa.substring(1,sa.length());

	while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	}
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String sa = scan.next(); sa scan.next() scan.next scan String sb = scan.next(); sb scan.next() scan.next scan String sc = scan.next(); sc scan.next() scan.next scan char turn = sa.charAt(0); turn sa.charAt(0) sa.charAt sa 0 sa = sa.substring(1,sa.length()) sa sa.substring(1,sa.length()) sa.substring sa 1 sa.length() sa.length sa while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	} true {
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	} if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    } turn == 'a' turn 'a' {
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    } if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		} sa.length() == 0 sa.length() sa.length sa 0 {
		    System.out.println("A");
		    break;
		} System.out.println("A") System.out.println System.out System System.out "A" break; {
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		} turn = sa.charAt(0) turn sa.charAt(0) sa.charAt sa 0 sa = sa.substring(1,sa.length()) sa sa.substring(1,sa.length()) sa.substring sa 1 sa.length() sa.length sa if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    } turn == 'b' turn 'b' {
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    } if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		} sb.length() == 0 sb.length() sb.length sb 0 {
		    System.out.println("B");
		    break;
		} System.out.println("B") System.out.println System.out System System.out "B" break; {
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		} turn = sb.charAt(0) turn sb.charAt(0) sb.charAt sb 0 sb = sb.substring(1,sb.length()) sb sb.substring(1,sb.length()) sb.substring sb 1 sb.length() sb.length sb {
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    } if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		} sc.length() == 0 sc.length() sc.length sc 0 {
		    System.out.println("C");
		    break;
		} System.out.println("C") System.out.println System.out System System.out "C" break; {
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		} turn = sc.charAt(0) turn sc.charAt(0) sc.charAt sc 0 sc = sc.substring(1,sc.length()) sc sc.substring(1,sc.length()) sc.substring sc 1 sc.length() sc.length sc String[] args args public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	/* 入力 */
	String sa = scan.next();
	String sb = scan.next();
	String sc = scan.next();

	/* 前準備 */
	char turn = sa.charAt(0);
	sa = sa.substring(1,sa.length());

	while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	}
    }
} public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	/* 入力 */
	String sa = scan.next();
	String sb = scan.next();
	String sc = scan.next();

	/* 前準備 */
	char turn = sa.charAt(0);
	sa = sa.substring(1,sa.length());

	while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	}
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	/* 入力 */
	String sa = scan.next();
	String sb = scan.next();
	String sc = scan.next();

	/* 前準備 */
	char turn = sa.charAt(0);
	sa = sa.substring(1,sa.length());

	while(true){
	    /* 次のターンを決める */
	    if(turn == 'a'){
		if(sa.length() == 0){
		    System.out.println("A");
		    break;
		}else{
		    turn = sa.charAt(0);
		    sa = sa.substring(1,sa.length());
		}
	    }else if(turn == 'b'){
		if(sb.length() == 0){
		    System.out.println("B");
		    break;
		}else{
		    turn = sb.charAt(0);
		    sb = sb.substring(1,sb.length());
		}
	    }else{
		if(sc.length() == 0){
		    System.out.println("C");
		    break;
		}else{
		    turn = sc.charAt(0);
		    sc = sc.substring(1,sc.length());
		}
	    }
	}
    }
}
