import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	} main {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) StringBuilder sa = new StringBuilder(in.next()); sa new StringBuilder(in.next()) StringBuilder sb = new StringBuilder(in.next()); sb new StringBuilder(in.next()) StringBuilder sc = new StringBuilder(in.next()); sc new StringBuilder(in.next()) char nextTurn = 'a'; nextTurn 'a' int N = sa.length() + sb.length() + sc.length(); N sa.length() + sb.length() + sc.length() sa.length() + sb.length() + sc.length() sa.length() sa.length sa sb.length() sb.length sb sc.length() sc.length sc while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		} true {
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		} if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			} nextTurn == 'a' nextTurn 'a' {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} if (sa.length() == 0) {
					System.out.println("A");
					break;
				} sa.length() == 0 sa.length() sa.length sa 0 {
					System.out.println("A");
					break;
				} System.out.println("A") System.out.println System.out System System.out "A" break; nextTurn = sa.charAt(0) nextTurn sa.charAt(0) sa.charAt sa 0 sa.delete(0, 1) sa.delete sa 0 1 if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			} nextTurn == 'b' nextTurn 'b' {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} if (sb.length() == 0) {
					System.out.println("B");
					break;
				} sb.length() == 0 sb.length() sb.length sb 0 {
					System.out.println("B");
					break;
				} System.out.println("B") System.out.println System.out System System.out "B" break; nextTurn = sb.charAt(0) nextTurn sb.charAt(0) sb.charAt sb 0 sb.delete(0, 1) sb.delete sb 0 1 {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			} if (sc.length() == 0) {
					System.out.println("C");
					break;
				} sc.length() == 0 sc.length() sc.length sc 0 {
					System.out.println("C");
					break;
				} System.out.println("C") System.out.println System.out System System.out "C" break; nextTurn = sc.charAt(0) nextTurn sc.charAt(0) sc.charAt sc 0 sc.delete(0, 1) sc.delete sc 0 1 in.close() in.close in String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sa = new StringBuilder(in.next());
		StringBuilder sb = new StringBuilder(in.next());
		StringBuilder sc = new StringBuilder(in.next());

		char nextTurn = 'a';
		int N = sa.length() + sb.length() + sc.length();
		while(true){
			if (nextTurn == 'a') {
				if (sa.length() == 0) {
					System.out.println("A");
					break;
				}
				nextTurn = sa.charAt(0);
				sa.delete(0, 1);
			} else if (nextTurn == 'b') {
				if (sb.length() == 0) {
					System.out.println("B");
					break;
				}
				nextTurn = sb.charAt(0);
				sb.delete(0, 1);
			} else {
				if (sc.length() == 0) {
					System.out.println("C");
					break;
				}
				nextTurn = sc.charAt(0);
				sc.delete(0, 1);
			}
		}
		in.close();
	}
}