#include <bits/stdc++.h>

using namespace std;

int main(int argc, const char *argv[]) {
  vector<string> vs(3);
  for (int i = 0; i < 3; ++i) {
    cin >> vs[i];
  }

  vector<int> cur(3, 0);
  int t = 0;
  char ans;
  while (true) {
    if (cur[t] >= vs[t].size()) {
      ans = 'A' + t;
      break;
    }

    cur[t]++;
    t = vs[t][cur[t] - 1] - 'a';
  }

  cout << ans << '\n';
}
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  if(s.size()==3){
	for(int i=2;i>=0;i--){
      cout << s.at(i);
    }
    cout << endl;
  }
  else{
    cout << s << endl;
  }
}
