#include<bits/stdc++.h>
using namespace std;
queue<char>a,b,c;
int main(){
 string al , bo ,chr ;
 cin >> al ;
 cin >> bo ;
 cin >> chr ;
 for(int i=0;i<al.size();i++){
    a.push(al[i]);
 }
 for(int i=0;i<bo.size();i++){
    b.push(bo[i]);
 }
 for(int i=0;i<chr.size();i++){
    c.push(chr[i]);
 }
 char curr = a.front();
 a.pop();
 while(true){
     if(curr=='a'){
        if(a.empty()){
          cout << "A" <<endl;
          return 0;
        }
        curr = a.front();
        a.pop();
     }
     else if(curr=='b'){
        if(b.empty()){
          cout << "B" <<endl;
          return 0;
        }
        curr=b.front();
        b.pop();
     }
     else if(curr=='c'){
        if(c.empty()){
          cout << "C" <<endl;
          return 0;
        }
        curr=c.front();
        c.pop();
     }
 }

 return  0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    string s[3];
    rep(i, 3) cin >> s[i];

    int t = 0;
    vector<int> idx(3);
    while (true) {
        if (s[t].size() == idx[t]) {
            cout << char('A' + t) << endl;
            return 0;
        }
        t = s[t][idx[t]++] - 'a';
    }

    return 0;
}
