#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

string s[3];
int p[3];
int len[3];
int k = 0;

int main() {
	for (int i = 0; i < 3; ++i) cin >> s[i], len[i] = s[i].size();
	while (1) {
		if (p[k] == len[k]) {
			printf("%c\n", k + 'A');
			break;
		}
		k = s[k][p[k]++] - 'a';
	}
	return 0;
}