#include <iostream>
using namespace std;

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