import java.io.IOException;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String aString = scanner.nextLine();
		String bString = scanner.nextLine();
		String cString = scanner.nextLine();

		int a=0;
		int b=0;
		int c=0;
		char start = 'a';
		while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

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

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String aString = scanner.nextLine();
		String bString = scanner.nextLine();
		String cString = scanner.nextLine();

		int a=0;
		int b=0;
		int c=0;
		char start = 'a';
		while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		}
	}
} Main public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String aString = scanner.nextLine();
		String bString = scanner.nextLine();
		String cString = scanner.nextLine();

		int a=0;
		int b=0;
		int c=0;
		char start = 'a';
		while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		}
	} main {
		Scanner scanner = new Scanner(System.in);
		String aString = scanner.nextLine();
		String bString = scanner.nextLine();
		String cString = scanner.nextLine();

		int a=0;
		int b=0;
		int c=0;
		char start = 'a';
		while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String aString = scanner.nextLine(); aString scanner.nextLine() scanner.nextLine scanner String bString = scanner.nextLine(); bString scanner.nextLine() scanner.nextLine scanner String cString = scanner.nextLine(); cString scanner.nextLine() scanner.nextLine scanner int a=0; a 0 int b=0; b 0 int c=0; c 0 char start = 'a'; start 'a' while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		} true {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		} if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			} start=='a' start 'a' {

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			} if(a==aString.length()){
					System.out.println("A");
					break;
				} a==aString.length() a aString.length() aString.length aString {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; start = aString.charAt(a) start aString.charAt(a) aString.charAt aString a a++ a if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			} start=='b' start 'b' {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			} if(b==bString.length()){
					System.out.println("B");
					break;
				} b==bString.length() b bString.length() bString.length bString {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; start = bString.charAt(b) start bString.charAt(b) bString.charAt bString b b++ b {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			} if(c==cString.length()){
					System.out.println("C");
					break;
				} c==cString.length() c cString.length() cString.length cString {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; start = cString.charAt(c) start cString.charAt(c) cString.charAt cString c c++ c String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String aString = scanner.nextLine();
		String bString = scanner.nextLine();
		String cString = scanner.nextLine();

		int a=0;
		int b=0;
		int c=0;
		char start = 'a';
		while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		}
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String aString = scanner.nextLine();
		String bString = scanner.nextLine();
		String cString = scanner.nextLine();

		int a=0;
		int b=0;
		int c=0;
		char start = 'a';
		while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		}
	}
} Main
import java.io.IOException;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String aString = scanner.nextLine();
		String bString = scanner.nextLine();
		String cString = scanner.nextLine();

		int a=0;
		int b=0;
		int c=0;
		char start = 'a';
		while (true) {
			if(start=='a'){

				if(a==aString.length()){
					System.out.println("A");
					break;
				}
				start = aString.charAt(a);
				a++;
			}else if (start=='b') {

				if(b==bString.length()){
					System.out.println("B");
					break;
				}
				start = bString.charAt(b);
				b++;
			}else {

				if(c==cString.length()){
					System.out.println("C");
					break;
				}
				start = cString.charAt(c);
				c++;
			}

		}
	}
}
