#include <bits/stdc++.h>
using namespace std;

int main()
{
	int tmp = 0;
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	while (true) {
		if (s[tmp].empty()) {
			break;
		}
		else {
			char t = s[tmp].front();
			s[tmp].erase(s[tmp].begin(), s[tmp].begin() + 1);
			tmp = (int)t - 'a';
		}
	}
	cout << (char)(tmp + 'A') << endl;
	return 0;
}
