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

int cups[4] = {};

int main() {
  string s;
  cups[1] = 1;
  while(cin>>s) {
    if(cups[s[0]-'A'+1]) cups[s[2]-'A'+1] = 1, cups[s[0]-'A'+1] = 0;
    if(cups[s[2]-'A'+1]) cups[s[2]-'A'+1] = 0, cups[s[0]-'A'+1] = 1;
  }
  for(int i=0; i<4; ++i)
    if(cups[i]) cout<<(char)(i+'A'-1)<<endl;
}