#include<iostream>
#include<string>

int main() {
	std::string s[3];
	for (int i = 0; i < 3; i++)std::cin >> s[i];
	char turn = 0;
	int idx[3] = { 0,0,0 };
	while (true) {
		if (s[turn].length() == idx[turn]) {
			printf("%c\n", turn + 'A');
			return 0;
		}
		idx[turn]++;
		turn = s[turn][idx[turn] - 1]-'a';
	}
}