#include <bits/stdc++.h>
using namespace std;

int main() {
  string S[3];
  cin >> S[0] >> S[1] >> S[2];

  char next = 'a';
  while (S[next - 'a'].size() > 0) {
    int tmp = next - 'a';
    next = S[tmp][0];
    S[tmp] = S[tmp].substr(1);
  }

  if (next == 'a') cout << "A" << endl;
  else if (next == 'b') cout << "B" << endl;
  else cout << "C" << endl;
}