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

int main() {
	string A, B, C;
	while (1) {
		cin >> A >> B;
		if (A == "A") {
			C = B;
		}
		else if (B == "A") {
			C = A;
		}
		if (C == "B"&&C == "C")break;
	}
	while (1) {
		cin >> A >> B;
		if (A == C) {
			C = B;
		}
		else if (B == C) {
			C = A;
		}
	}
	cout << C << endl;
	return 0;
}