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

int main(){
	string a, b, c;
	cin >> a >> b >> c;
	char judge='a';
	int numa=a.size();
	int numb=b.size();
	int numc=c.size();
	bool fin=true;
	while(fin){
		if(judge=='a'){
			if(numa==0){
				fin=false;
			}
			if(numa>0){
				judge=a.at(a.size()-numa);
				numa--;
			}
		}
		if(judge=='b'){
			if(numb==0) fin=false;
			if(numb>0){
				judge=b.at(b.size()-numb);
				numb--;
			}
		}
		if(judge=='c'){
			if(numc==0) fin=false;
			if(numc>0){
				judge=c.at(c.size()-numc);
				numc--;
			}
		}
	}
	if(judge=='a') cout << "A" << endl;
	if(judge=='b') cout << "B" << endl;
	if(judge=='c') cout << "C" << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

queue<char>q[3];


void scan(int n)
{
	char c;
	while((c=getchar() )!='\n')
		{
			q[n].push(c);
		}
}
int main()
{
    fast;
    
    scan(0);
    scan(1);
    scan(2);
    

	ll k=0;
	while(!q[k].empty())
	{
		char c=q[k].front();
		q[k].pop();
		
		k=c-'a';
	}
	

  cout<<char(k +'A');
  
    
   
}

		
	
	
	
	
