#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	string s[3];
	for (int i = 0; i < 3; i++) cin >> s[i];
	int idx[3] = {};
	int turn = 0;
	while (1) {
		if (idx[turn] == s[turn].size()) {
			printf("%c\n", 'A' + turn);
			return 0;
		}
		int nturn = s[turn][idx[turn]] - 'a';
		idx[turn]++;
		turn = nturn;
	}
}