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

int main()
{
	char x, y;
	string str;
	int posi = 1;
	while (cin >> str) {
		x = str[0];
		y = str[2];
		//(char)x = min((int)x, (int)y);
		//(char)y = max((int)x, (int)y);
		if (x == 'B' && y == 'A') { x == 'A'; y == 'B'; }
		else if (x == 'C' && y == 'A') { x == 'A'; y == 'C'; }
		else if (x == 'C' && y == 'B') { x == 'B'; y == 'C'; }

		if (posi == 1) {
			if (x == 'A' && y == 'B')posi = 2;
			else if (x == 'A' && y == 'C')posi = 3;
		}
		else if (posi == 2) {
			if (x == 'A' && y == 'B')posi = 1;
			else if (x == 'B' && y == 'C')posi = 3;
		}
		else if (posi == 3) {
			if (x == 'A' && y == 'C')posi = 1;
			else if (x == 'B' && y == 'C')posi = 2;
		}
	}
	if (posi == 1)cout << "A" << endl;
	else if (posi == 2)cout << "B" << endl;
	else if (posi == 3)cout << "C" << endl;
    return 0;
}