#include <stdio.h>
using namespace std;
int main()
{
	char cards[3][101];
	char ptr[3];
	char next = 0;

	for(int i = 0; i < 3; i++){
		scanf("%s", &cards[i]);
		ptr[i] = 0;
	}

	while(1){

		char card = cards[next][ptr[next]++];
		if(card == '\0')
			break;
		next = card - 'a';
	}

	printf("%c", next + 'A');
	return 0;
}
