#include<iostream>
using namespace std;
int main(){
  
  char s[3][105];
  for(int i=0;i<3;i++){
    cin>>s[i];
  }
  int play=0;
  int pos[3]={0,0,0};
  char ans;
  while(1){
    pos[play]++;
    play=s[play][pos[play]-1]-'a';
    if(s[play][pos[play]]=='\0'){
      ans='A'+play;
      break;
    }
  }
  
  cout<<ans<<"\n";
  return 0;
}
