#include<iostream>

using namespace std;

int main(){

    string s[3];
    cin>> s[0]>> s[1]>> s[2];

    int turn=0;
    while(1){
        if(s[turn].empty()){
            cout<< (char)('A'+turn)<< endl;
            return 0;
        }
        int next=s[turn].front()-'a';
        s[turn]=s[turn].substr(1);
        turn=next;
    }

    return 0;
}
