#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int s(char c) { return c == 'A' ? 0 : c == 'B' ? 1 : c == 'C' ? 2 : 0; }

int main()
{
	vector<char> cup(3);
	cup[0] = 'A', cup[1] = 'B', cup[2] = 'C';

	char c1, c2;
	while (scanf("%c,%c", &c1, &c2) != EOF)
		swap(cup[s(c1)], cup[s(c2)]);

	for (int i = 0; i < cup.size(); ++i)
		if (cup[i] == 'A') cout << cup[s(i)] << endl;

	return 0;
}