import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		int a = 0,b = 0,c = 0;
		char point = 'a';
		while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		}

	}

	public static boolean hasNext(char[] ary,int point){
		if(ary.length == point) return false;
		return true;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		int a = 0,b = 0,c = 0;
		char point = 'a';
		while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		}

	}

	public static boolean hasNext(char[] ary,int point){
		if(ary.length == point) return false;
		return true;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		int a = 0,b = 0,c = 0;
		char point = 'a';
		while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		}

	} main {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		int a = 0,b = 0,c = 0;
		char point = 'a';
		while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] A = sc.next().toCharArray(); A sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] B = sc.next().toCharArray(); B sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] C = sc.next().toCharArray(); C sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc int a = 0 a 0 b = 0 b 0 c = 0; c 0 char point = 'a'; point 'a' while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		} true {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		} if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			} point == 'a' point 'a' {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			} if(!hasNext(A, a)){
					System.out.println('A');
					break;
				} !hasNext(A, a) hasNext(A, a) hasNext A a {
					System.out.println('A');
					break;
				} System.out.println('A') System.out.println System.out System System.out 'A' break; point = A[a] point A[a] A a a++ a if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			} point == 'b' point 'b' {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			} if(!hasNext(B, b)){
					System.out.println('B');
					break;
				} !hasNext(B, b) hasNext(B, b) hasNext B b {
					System.out.println('B');
					break;
				} System.out.println('B') System.out.println System.out System System.out 'B' break; point = B[b] point B[b] B b b++ b {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			} if(!hasNext(C, c)){
					System.out.println('C');
					break;
				} !hasNext(C, c) hasNext(C, c) hasNext C c {
					System.out.println('C');
					break;
				} System.out.println('C') System.out.println System.out System System.out 'C' break; point = C[c] point C[c] C c c++ c String[] args args public static boolean hasNext(char[] ary,int point){
		if(ary.length == point) return false;
		return true;
	} hasNext {
		if(ary.length == point) return false;
		return true;
	} if(ary.length == point) return false; ary.length == point ary.length ary ary.length point return false; false return true; true char[] ary ary int point point public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		int a = 0,b = 0,c = 0;
		char point = 'a';
		while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		}

	}

	public static boolean hasNext(char[] ary,int point){
		if(ary.length == point) return false;
		return true;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		int a = 0,b = 0,c = 0;
		char point = 'a';
		while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		}

	}

	public static boolean hasNext(char[] ary,int point){
		if(ary.length == point) return false;
		return true;
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		int a = 0,b = 0,c = 0;
		char point = 'a';
		while(true) {
			if(point == 'a') {
				if(!hasNext(A, a)){
					System.out.println('A');
					break;
				}
				point = A[a];
				a++;
			}else if(point == 'b') {
				if(!hasNext(B, b)){
					System.out.println('B');
					break;
				}
				point = B[b];
				b++;
			}else {
				if(!hasNext(C, c)){
					System.out.println('C');
					break;
				}
				point = C[c];
				c++;
			}

		}

	}

	public static boolean hasNext(char[] ary,int point){
		if(ary.length == point) return false;
		return true;
	}
}