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

string s[128];

int main() {
  cin >> s['a'] >> s['b'] >> s['c'];
  for (char c = 'a'; c <= 'c'; c++)
    reverse(s[c].begin(), s[c].end());
  char c = 'a';
  while (!s[c].empty()) {
   	char d = s[c].back(); s[c].pop_back();
    c = d;
  }
  cout << (char)toupper(c) << endl;
}