#include <bits/stdc++.h>
std::string s[3];
int p[3];
int len[3];
int k = 0;

int main() {
    for (int i = 0; i < 3; ++i) std::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;
}