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



int main(){
	string S[3];
	cin>>S[0]>>S[1]>>S[2];
	int now[3]={};
	int player = 0;
	
	while(true){
		if(now[player]==S[player].size()){
			cout<<(char)('A'+player)<<endl;
			return 0;
		}
		int a = now[player];
		now[player]++;
		player=S[player][a]-'a';
	}
	
	
	
	return 0;
}