#include <iostream>
#include <cstdio>

using namespace std;

int main() {

	int t, x[64];
	char i, j;

	x[0]=1;
	x[1]=0;
	x[2]=0;

	while(scanf("%s %s", &i, &j)!=EOF) {
		if(i=='A'&&j=='B'||i=='B'&&j=='A') {
			t=x[0];
			x[0]=x[1];
			x[1]=t;
		}
		else if(i=='B'&&j=='C'||i=='C'&&j=='B') {
			t=x[1];
			x[1]=x[2];
			x[2]=t;
		}
		else if(i=='C'&&j=='A'||i=='A'&&j=='C') {
			t=x[2];
			x[2]=x[0];
			x[0]=t;
		}
	}

	if(x[0]==1)
		cout << "A" << endl;
	else if(x[1]==1)
		cout << "B" << endl;
	else
		cout << "C" << endl;

	return 0;

}