#include <iostream>
using namespace std;

int main(){
    string S[3];
    for(int i=0;i<3;i++) cin >> S[i];
    int now = 0;
    int id[3] = {0,0,0};
    while(true){
        if(id[now]==S[now].size()){
            char c = 'A'+now;
            cout << c << endl;
            return 0;
        }
        id[now]++;
        now = S[now][id[now]-1]-'a';
    }
}