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