import java.util.Scanner;

/**
 * https://abc045.contest.atcoder.jp/tasks/abc045_b
 */
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();
		sc.close();
		
		int ia = 1;
		int ib = 0;
		int ic = 0;
		char current = A[0];
		String ans = null;
		while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		}
		
		System.out.println(ans);
		
	}

} 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();
		sc.close();
		
		int ia = 1;
		int ib = 0;
		int ic = 0;
		char current = A[0];
		String ans = null;
		while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		}
		
		System.out.println(ans);
		
	}

} 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();
		sc.close();
		
		int ia = 1;
		int ib = 0;
		int ic = 0;
		char current = A[0];
		String ans = null;
		while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		}
		
		System.out.println(ans);
		
	} main {
		
		Scanner sc = new Scanner(System.in);
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();
		sc.close();
		
		int ia = 1;
		int ib = 0;
		int ic = 0;
		char current = A[0];
		String ans = null;
		while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		}
		
		System.out.println(ans);
		
	} 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 sc.close() sc.close sc int ia = 1; ia 1 int ib = 0; ib 0 int ic = 0; ic 0 char current = A[0]; current A[0] A 0 String ans = null; ans null while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		} ans==null ans null {
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		} switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			} current case 'a': 'a' case 'a': if(ia==A.length) ans = "A";
				else current = A[ia++]; ia==A.length ia A.length A A.length ans = "A" ans "A" current = A[ia++] current A[ia++] A ia++ ia break; case 'b': 'b' case 'b': if(ib==B.length) ans = "B";
				else current = B[ib++]; ib==B.length ib B.length B B.length ans = "B" ans "B" current = B[ib++] current B[ib++] B ib++ ib break; case 'c': 'c' case 'c': if(ic==C.length) ans = "C";
				else current = C[ic++]; ic==C.length ic C.length C C.length ans = "C" ans "C" current = C[ic++] current C[ic++] C ic++ ic break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args 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();
		sc.close();
		
		int ia = 1;
		int ib = 0;
		int ic = 0;
		char current = A[0];
		String ans = null;
		while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		}
		
		System.out.println(ans);
		
	}

} 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();
		sc.close();
		
		int ia = 1;
		int ib = 0;
		int ic = 0;
		char current = A[0];
		String ans = null;
		while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		}
		
		System.out.println(ans);
		
	}

} Main
import java.util.Scanner;

/**
 * https://abc045.contest.atcoder.jp/tasks/abc045_b
 */
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();
		sc.close();
		
		int ia = 1;
		int ib = 0;
		int ic = 0;
		char current = A[0];
		String ans = null;
		while(ans==null){
			switch(current){
			case 'a':
				if(ia==A.length) ans = "A";
				else current = A[ia++];
				break;
			case 'b':
				if(ib==B.length) ans = "B";
				else current = B[ib++];
				break;
			case 'c':
				if(ic==C.length) ans = "C";
				else current = C[ic++];
				break;
			}
		}
		
		System.out.println(ans);
		
	}

}