#include<bits/stdc++.h>
using namespace std;
int main(){
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  
  int i = 0;
  while(1){
    if(s[i].size() == 0){
      cout << (char)(i + 'A');
      return 0;
    }
    char c = s[i].at(0);
    s[i] = s[i].substr(1,s[i].size()); 
    i = c - 'a';
  }
}
    