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

int main(){
    char i,j;
    int a[3] = {1,0,0};
    int tmp;
    while(scanf("%c,%c",&i,&j) != EOF){
        if((i == 'A' && j == 'B') || (i == 'B' && j == 'A')){
            tmp=a[0];
            a[0]=a[1];
            a[1]=tmp;
        }
        else if((i == 'B' && j == 'C') || (i == 'C' && j == 'B')){
            tmp=a[1];
            a[1]=a[2];
            a[2]=tmp;
        }
        else if((i == 'A' && j == 'C') || (i == 'C' && j == 'A')){
            tmp=a[0];
            a[0]=a[2];
            a[2]=tmp;
        }
    }
    for(int i=0;i<3;i++){
        if(a[i] == 1){
            if(i == 0) cout << "A" << endl;
            else if(i == 1) cout << "B" << endl;
            else if(i == 2) cout << "C" << endl;
        }
    }
}