#include <stdio.h>
#include <iostream>

using namespace std;

int main() {

	char a,b,d;
	int k[3] = {1};
	int kari;
	int i,j;

	while (cin >> a >> d >> b) {
		if (a == 'A') {
			i = 0;
		} else if (a == 'B') {
			i = 1;
		} else if (a == 'C'){
			i = 2;
		} else {
			break;
		}

		if (d != ',') {
			break;
		}

		if (b == 'A') {
			j = 0;
		} else if (b == 'B') {
			j = 1;
		} else if (b == 'C'){
			j = 2;
		} else {
			break;
		}

		kari = k[i];
		k[i] = k[j];
		k[j] = kari;

	}

	if (k[0] == 1) {
		cout << 'A' << endl;
	} else if (k[1] == 1) {
		cout << 'B' << endl;
	} else {
		cout << 'C' << endl;
	}

	return 0;
}