#include <iostream>

using namespace std;

int main()
{
    string str[3];
    cin >> str[0] >> str[1] >> str[2];

    int ptr[3] = {};
    int ind = 0;
    while(1){
        if(ptr[ind] >= str[ind].size()){
            break;
        }
        ind = str[ind][ptr[ind]++] - 'a';
    }
    cout << (char)('A' + ind) << endl;
    return 0;
}
