#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    char turn = 'a';
    string a, b, c;
    int i = 0, j = 0, k = 0;
    cin >> a >> b >> c;
    while (i <= a.size() && j <= b.size() && k <= c.size()) 
    {
        if (turn == 'a') 
            turn = a[i++];
        else if (turn == 'b') 
            turn = b[j++];
        else 
            turn = c[k++];
    }
    if (i > a.size()) cout << "A" << endl;
    else if (j > b.size()) cout << "B" << endl;
    else cout << "C" << endl;
}
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

string s[3];
int cnt[3];

int main() {
  cin >> s[0] >> s[1] >> s[2];
  int cur = 0;
  while (cnt[cur] < s[cur].size()) {
    int next = s[cur][cnt[cur]] - 'a';
    ++cnt[cur];
    cur = next;
  }
  char ans = 'A' + cur;
  cout << ans;
}
