#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  string sa,sb,sc; cin >> sa >> sb >> sc;
  int a = 0, b = 0, c = 0;
  char now = 'a';
  char winner;
  while(true){
    if(now == 'a'){
      if(a == sa.size()){
        winner = 'A';
        break;
      }
      now = sa[a];
      a++;
    }else if(now == 'b'){
      if(b == sb.size()){
        winner = 'B';
        break;
      }
      now = sb[b];
      b++;
    }else if(now == 'c'){
      if(c == sc.size()){
        winner = 'C';
        break;
      }
      now = sc[c];
      c++;
    }
  }
  cout << winner;
  cout << "\n";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s[3];
    for(int i = 0; i < 3; i++) {
        cin >> s[i];
    }
    int nowTurn = 0;
    int nowId[3] = {0, 0, 0};
    while(1) {
        if(nowId[nowTurn] >= s[nowTurn].size()) {
            cout << (char)('A' + nowTurn) << endl;
            break;
        }
        int nxtTurn = s[nowTurn][nowId[nowTurn]] - 'a';
        nowId[nowTurn]++;
        nowTurn = nxtTurn;
    }
}