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();
		StringBuilder A = new StringBuilder();
		StringBuilder B = new StringBuilder();
		StringBuilder C = new StringBuilder();
		A.append(a);
		B.append(b);
		C.append(c);
		char next = 'a';
		for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		}

	}
	public static int sample(int n) {
		return n;
	}

} 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();
		StringBuilder A = new StringBuilder();
		StringBuilder B = new StringBuilder();
		StringBuilder C = new StringBuilder();
		A.append(a);
		B.append(b);
		C.append(c);
		char next = 'a';
		for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		}

	}
	public static int sample(int n) {
		return n;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(),b=sc.next(),c=sc.next();
		StringBuilder A = new StringBuilder();
		StringBuilder B = new StringBuilder();
		StringBuilder C = new StringBuilder();
		A.append(a);
		B.append(b);
		C.append(c);
		char next = 'a';
		for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		}

	} main {
		Scanner sc = new Scanner(System.in);
		String a = sc.next(),b=sc.next(),c=sc.next();
		StringBuilder A = new StringBuilder();
		StringBuilder B = new StringBuilder();
		StringBuilder C = new StringBuilder();
		A.append(a);
		B.append(b);
		C.append(c);
		char next = 'a';
		for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		}

	} 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 StringBuilder A = new StringBuilder(); A new StringBuilder() StringBuilder B = new StringBuilder(); B new StringBuilder() StringBuilder C = new StringBuilder(); C new StringBuilder() A.append(a) A.append A a B.append(b) B.append B b C.append(c) C.append C c char next = 'a'; next 'a' for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		} int i=0; int i=0; i 0 i<301 i 301 i++ i++ i {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		} {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		} if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			} next=='a' next 'a' {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			} if(A.length()==0) {
					System.out.println("A");
					break;
				} 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; next = A.charAt(0) next A.charAt(0) A.charAt A 0 A.deleteCharAt(0) A.deleteCharAt A 0 if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			} next=='b' next 'b' {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			} if(B.length()==0){
					System.out.println("B");
					break;
				} 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; next = B.charAt(0) next B.charAt(0) B.charAt B 0 B.deleteCharAt(0) B.deleteCharAt B 0 {
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			} if(C.length()==0) {
					System.out.println("C");
					break;
				} 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; next = C.charAt(0) next C.charAt(0) C.charAt C 0 C.deleteCharAt(0) C.deleteCharAt C 0 String[] args args public static int sample(int n) {
		return n;
	} sample {
		return n;
	} return n; n int n n 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();
		StringBuilder A = new StringBuilder();
		StringBuilder B = new StringBuilder();
		StringBuilder C = new StringBuilder();
		A.append(a);
		B.append(b);
		C.append(c);
		char next = 'a';
		for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		}

	}
	public static int sample(int n) {
		return n;
	}

} 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();
		StringBuilder A = new StringBuilder();
		StringBuilder B = new StringBuilder();
		StringBuilder C = new StringBuilder();
		A.append(a);
		B.append(b);
		C.append(c);
		char next = 'a';
		for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		}

	}
	public static int sample(int n) {
		return n;
	}

} 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();
		StringBuilder A = new StringBuilder();
		StringBuilder B = new StringBuilder();
		StringBuilder C = new StringBuilder();
		A.append(a);
		B.append(b);
		C.append(c);
		char next = 'a';
		for(int i=0;i<301;i++) {
			if(next=='a') {
				if(A.length()==0) {
					System.out.println("A");
					break;
				}
				next = A.charAt(0);
				A.deleteCharAt(0);
			}else if(next=='b') {
				if(B.length()==0){
					System.out.println("B");
					break;
				}
				next = B.charAt(0);
				B.deleteCharAt(0);
			}else{
				if(C.length()==0) {
					System.out.println("C");
					break;
				}
				next = C.charAt(0);
				C.deleteCharAt(0);
			}
		}

	}
	public static int sample(int n) {
		return n;
	}

}
