#include <bits/stdc++.h>

using namespace std;

int main()
{
	string s[3];
	for (auto&& si : s)
	{
		cin >> si;
		reverse(si.begin(), si.end());
	}
	int r = s[0].back();
	s[0].pop_back();
	while (s[r-'a'].size() > 0)
	{
		int tmp = s[r-'a'].back();
		s[r-'a'].pop_back();
		r = tmp;
	}
	cout << (char)(r-'a'+'A') << endl;

	return 0;
}
