import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String next = "a";
		while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		}
		System.out.println(next.toUpperCase());
	}

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

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String next = "a";
		while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		}
		System.out.println(next.toUpperCase());
	}

} Main public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String next = "a";
		while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		}
		System.out.println(next.toUpperCase());
	} main {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String next = "a";
		while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		}
		System.out.println(next.toUpperCase());
	} 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 String next = "a"; next "a" while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		} true {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		} if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			} next.equals("a") && a.length()>0 next.equals("a") next.equals next "a" a.length()>0 a.length() a.length a 0 {
				next = a.substring(0, 1);
				a = a.substring(1);
			} next = a.substring(0, 1) next a.substring(0, 1) a.substring a 0 1 a = a.substring(1) a a.substring(1) a.substring a 1 if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			} next.equals("b") && b.length()>0 next.equals("b") next.equals next "b" b.length()>0 b.length() b.length b 0 {
				next = b.substring(0, 1);
				b = b.substring(1);
			} next = b.substring(0, 1) next b.substring(0, 1) b.substring b 0 1 b = b.substring(1) b b.substring(1) b.substring b 1 if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			} c.length()>0 c.length() c.length c 0 {
				next = c.substring(0, 1);
				c = c.substring(1);
			} next = c.substring(0, 1) next c.substring(0, 1) c.substring c 0 1 c = c.substring(1) c c.substring(1) c.substring c 1 {
				break;
			} break; System.out.println(next.toUpperCase()) System.out.println System.out System System.out next.toUpperCase() next.toUpperCase next String[] args args public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String next = "a";
		while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		}
		System.out.println(next.toUpperCase());
	}

} public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String next = "a";
		while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		}
		System.out.println(next.toUpperCase());
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String next = "a";
		while(true) {
			if(next.equals("a") && a.length()>0) {
				next = a.substring(0, 1);
				a = a.substring(1);
			} else if(next.equals("b") && b.length()>0) {
				next = b.substring(0, 1);
				b = b.substring(1);
			} else if(c.length()>0){
				next = c.substring(0, 1);
				c = c.substring(1);
			} else {
				break;
			}
		}
		System.out.println(next.toUpperCase());
	}

}