#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
  string line;
  char ball = 'A';
  while (getline(cin, line)) {
    stringstream s;
    s << line;
    char a, b, c;
    s >> a >> b >> c;
    if (ball == a) ball = c;
    else if (ball == c) ball = a;
  }
  cout << ball << endl;
}