//8 may 2020
//count of solved problems : 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
string s[3];
int main(){
	cin>>s[0]>>s[1]>>s[2];
	int t=0;
	while(true){
		if(s[t].size()==0){
			cout<<char(t+'A');
			return 0;
		}
		char c=s[t][0];
		s[t].erase(s[t].begin());
		t=c-'a';
	}
	
}

