#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;

int main(){
    std::vector<string> d(3);
    for(ll i=0;i<3;++i){
        cin>>d[i];
    }
    ll a=0,b=0,c=0;
    char now='a';
    while(1){
        switch(now){
            case 'a':
                if(a>=d[0].length()){
                    cout<<char(now+'A'-'a');
                    return 0;
                }
                now=d[0][a];
                a++;
            break;
            case 'b':
                if(b>=d[1].length()){
                    cout<<char(now+'A'-'a');
                    return 0;
                }
                now=d[1][b];
                b++;
            break;
            case 'c':
                if(c>=d[2].length()){
                    cout<<char(now+'A'-'a');
                    return 0;
                }
                now=d[2][c];
                c++;
            break;
        }
    }
    return 0;
}
#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');
  
    
   
}

		
	
	
	
	
