#include<iostream>
#include<string>
using namespace std;
string s[4];
int main()
{
	cin>>s[1];
	cin>>s[2];
	cin>>s[3];
	int po[4]={0},now=1;
	while(po[now]<s[now].length())
	{
		int to=s[now][po[now]++]-'a'+1;
		now=to;
	}
	cout<<(char)('A'+now-1)<<endl;
	return 0;
}