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

int main() {
  string s;
  char ans='A';
  while(cin >> s) {
    if(s[0]==ans) ans=s[2];
    else if(s[2]==ans) ans=s[0];
  }
  cout << ans << endl;
  return 0;
}
