#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int turn = 0;
  string ans;
  
  while(1) {
    if (s[turn].empty()) {
      ans = turn + 'A';
      break;
    }
    int tmp = s[turn][0] - 'a';
    s[turn].erase(0, 1);
    turn = tmp;
  }
  cout << ans << endl;
}