#include<iostream>
using namespace std;
int main()
{
	string s[3];cin>>s[0]>>s[1]>>s[2];
	int f=0,c[3]={};
	for(;;)
	{
		if(c[f]==s[f].size())
		{
			cout<<char('A'+f)<<endl;
			return 0;
		}
		else
		{
			f=s[f][c[f]++]-'a';
		}
	}
}
