import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String Sa = scanner.next();
		String Sb = scanner.next();
		String Sc = scanner.next();

		char[][] C = new char[3][100];
		C[0] = Sa.toCharArray();
		C[1] = Sb.toCharArray();
		C[2] = Sc.toCharArray();

		int[] t = new int[3];
		int now = 0;
		String ans = "";
		while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		}
		System.out.println(ans);
		scanner.close();
	}

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

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String Sa = scanner.next();
		String Sb = scanner.next();
		String Sc = scanner.next();

		char[][] C = new char[3][100];
		C[0] = Sa.toCharArray();
		C[1] = Sb.toCharArray();
		C[2] = Sc.toCharArray();

		int[] t = new int[3];
		int now = 0;
		String ans = "";
		while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		}
		System.out.println(ans);
		scanner.close();
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String Sa = scanner.next();
		String Sb = scanner.next();
		String Sc = scanner.next();

		char[][] C = new char[3][100];
		C[0] = Sa.toCharArray();
		C[1] = Sb.toCharArray();
		C[2] = Sc.toCharArray();

		int[] t = new int[3];
		int now = 0;
		String ans = "";
		while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		}
		System.out.println(ans);
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		String Sa = scanner.next();
		String Sb = scanner.next();
		String Sc = scanner.next();

		char[][] C = new char[3][100];
		C[0] = Sa.toCharArray();
		C[1] = Sb.toCharArray();
		C[2] = Sc.toCharArray();

		int[] t = new int[3];
		int now = 0;
		String ans = "";
		while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		}
		System.out.println(ans);
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String Sa = scanner.next(); Sa scanner.next() scanner.next scanner String Sb = scanner.next(); Sb scanner.next() scanner.next scanner String Sc = scanner.next(); Sc scanner.next() scanner.next scanner char[][] C = new char[3][100]; C new char[3][100] 3 100 C[0] = Sa.toCharArray() C[0] C 0 Sa.toCharArray() Sa.toCharArray Sa C[1] = Sb.toCharArray() C[1] C 1 Sb.toCharArray() Sb.toCharArray Sb C[2] = Sc.toCharArray() C[2] C 2 Sc.toCharArray() Sc.toCharArray Sc int[] t = new int[3]; t new int[3] 3 int now = 0; now 0 String ans = ""; ans "" while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		} true {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		} switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			} C[now][t[now]] C[now] C now t[now] t now case 'a': 'a' case 'a': t[now]++ t[now] t now now = 0 now 0 break; case 'b': 'b' case 'b': t[now]++ t[now] t now now = 1 now 1 break; case 'c': 'c' case 'c': t[now]++ t[now] t now now = 2 now 2 break; if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			} t[0]==Sa.length()&&now==0 t[0]==Sa.length() t[0] t 0 Sa.length() Sa.length Sa now==0 now 0 {
				ans = "A";
				break;
			} ans = "A" ans "A" break; if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			} t[1]==Sb.length()&&now==1 t[1]==Sb.length() t[1] t 1 Sb.length() Sb.length Sb now==1 now 1 {
				ans = "B";
				break;
			} ans = "B" ans "B" break; if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			} t[2]==Sc.length()&&now==2 t[2]==Sc.length() t[2] t 2 Sc.length() Sc.length Sc now==2 now 2 {
				ans = "C";
				break;
			} ans = "C" ans "C" break; System.out.println(ans) System.out.println System.out System System.out ans scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String Sa = scanner.next();
		String Sb = scanner.next();
		String Sc = scanner.next();

		char[][] C = new char[3][100];
		C[0] = Sa.toCharArray();
		C[1] = Sb.toCharArray();
		C[2] = Sc.toCharArray();

		int[] t = new int[3];
		int now = 0;
		String ans = "";
		while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		}
		System.out.println(ans);
		scanner.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String Sa = scanner.next();
		String Sb = scanner.next();
		String Sc = scanner.next();

		char[][] C = new char[3][100];
		C[0] = Sa.toCharArray();
		C[1] = Sb.toCharArray();
		C[2] = Sc.toCharArray();

		int[] t = new int[3];
		int now = 0;
		String ans = "";
		while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		}
		System.out.println(ans);
		scanner.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String Sa = scanner.next();
		String Sb = scanner.next();
		String Sc = scanner.next();

		char[][] C = new char[3][100];
		C[0] = Sa.toCharArray();
		C[1] = Sb.toCharArray();
		C[2] = Sc.toCharArray();

		int[] t = new int[3];
		int now = 0;
		String ans = "";
		while(true) {
			switch(C[now][t[now]]) {
			case 'a':
				t[now]++;
				now = 0;
				break;
			case 'b':
				t[now]++;
				now = 1;
				break;
			case 'c':
				t[now]++;
				now = 2;
				break;
			}

			if(t[0]==Sa.length()&&now==0) {
				ans = "A";
				break;
			}
			if(t[1]==Sb.length()&&now==1) {
				ans = "B";
				break;
			}
			if(t[2]==Sc.length()&&now==2) {
				ans = "C";
				break;
			}
		}
		System.out.println(ans);
		scanner.close();
	}

}
