#include <iostream>
using namespace std;

int main()
{
	char c[4], a = 'A';

	while (cin >> c) {
		if (a == c[0])
			a = c[2];
		else if (a == c[2])
			a = c[0];
	}

	cout << a << endl;

	return 0;
}
