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

int main(){
	string S[3];
	cin >> S[0] >> S[1] >> S[2];
	int now = 0, old = 0;
	while(1){
//		printf("now = %d\n", now);
		if(S[now].size() == 0){
			printf("%c\n", (char)((int)'A' + now));
			return 0;
		}
		else{
			now = (int)S[now][0] - (int)'a';
			S[old].erase(S[old].begin());
			old = now;
		}
	}
}