#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<string> s(3);
  cin >> s.at(0) >>s.at(1) >>s.at(2);
  int now = 0;
  while(true){
    if(s.at(now) == ""){
      cout << char( 'A' +now);
      return 0;
    }
    char t = s.at(now).at(0);
    s.at(now).erase(s.at(now).begin());

    now = t -'a';
    
  }
}