#include<cstdio>

using namespace std;

int main(){
	char s[3][110];
	scanf("%s %s %s", s[0], s[1], s[2]);
	int p[3] = {}, t = 0;
	while(1){
		if(s[t][p[t]] == '\0') break;
		t = s[t][p[t]++] - 'a';
	}
	printf("%c\n", "ABC"[t]);
	return 0;
}