#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    string a[3];
    cin >> a[0] >> a[1] >> a[2];
    int next = 0;
    while(1){
        if(a[next].empty()){
            printf("%c\n",next+'A');
            break;
        }
        int c = a[next].front()-'a';
        a[next].erase(a[next].begin());
        next = c;
    }
}   