import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()};

		int turn = 'a';
		while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		}
		System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C");
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()};

		int turn = 'a';
		while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		}
		System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C");
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()};

		int turn = 'a';
		while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		}
		System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C");
	} main {
		Scanner sc = new Scanner(System.in);

		String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()};

		int turn = 'a';
		while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		}
		System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()}; s {sc.nextLine(), sc.nextLine(), sc.nextLine()} sc.nextLine() sc.nextLine sc sc.nextLine() sc.nextLine sc sc.nextLine() sc.nextLine sc int turn = 'a'; turn 'a' while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		} true {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		} if (s[turn - 'a'].length() == 0) {
				break;
			} s[turn - 'a'].length() == 0 s[turn - 'a'].length() s[turn - 'a'].length s[turn - 'a'] s turn - 'a' turn 'a' 0 {
				break;
			} break; char c = s[turn - 'a'].charAt(0); c s[turn - 'a'].charAt(0) s[turn - 'a'].charAt s[turn - 'a'] s turn - 'a' turn 'a' 0 s[turn - 'a'] = s[turn - 'a'].substring(1) s[turn - 'a'] s turn - 'a' turn 'a' s[turn - 'a'].substring(1) s[turn - 'a'].substring s[turn - 'a'] s turn - 'a' turn 'a' 1 turn = c turn c System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C") System.out.println System.out System System.out turn == 'a' ? "A" : turn == 'b' ? "B" : "C" turn == 'a' turn 'a' "A" turn == 'b' ? "B" : "C" turn == 'b' turn 'b' "B" "C" String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()};

		int turn = 'a';
		while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		}
		System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C");
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()};

		int turn = 'a';
		while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		}
		System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C");
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String[] s = {sc.nextLine(), sc.nextLine(), sc.nextLine()};

		int turn = 'a';
		while (true) {
			if (s[turn - 'a'].length() == 0) {
				break;
			}
			char c = s[turn - 'a'].charAt(0);
			s[turn - 'a'] = s[turn - 'a'].substring(1);
			turn = c;
		}
		System.out.println(turn == 'a' ? "A" : turn == 'b' ? "B" : "C");
	}
}

