#include <iostream>
#include <string>

using namespace std;

int main()
{
    string S[3];
    for (string &s: S)
        cin>>s;
    int c = 0;
    while (true)
    {
        if (S[c].empty())
            break;
        char t = S[c][0];
        S[c].erase(S[c].begin());
        c = t-'a';
    }
    cout<<"ABC"[c]<<endl;
}
