#include<stdio.h>
int main(void){
   char s[10], o[10];
   int S[10], C[10];
   C[1] = 1; C[2] = 0; C[3] = 0;
   while ( scanf("%c,%c", s, o) != EOF ) {
      printf("%c\n", s[0], o[0]);
      if ( s[0] == 'A' ) {S[0] = 1;/*printf("keya\n");*/}
      else if ( s[0] == 'B' ) S[0] = 2;
      else if ( s[0] == 'C' ) S[0] = 3;
      if ( o[0] == 'A' ) S[1] = 1;
      else if ( o[0] == 'B' ) {S[1] = 2;/*printf("keya\n");*/}
      else if ( o[0] == 'C' ) {S[1] = 3;/*printf("keyb;\n");*/}
      if ( C [S[0]] == 1 ) { C[S[0]] = 0; C[S[1]] = 1; }
      else if ( C[S[1]] == 1 ) { C[S[0]] = 1; C[S[1]] = 0; }
      printf("key\n");
      /*printf("S[0]:%d S[1]:%d\n", S[0], S[1]);*/
      printf("A:%d B:%d C:%d\n", C[1], C[2], C[3]);
      /*if ( C[1] == 1 ) printf("A\n");
      else if ( C[2] == 1 ) printf("B\n");
      else if ( C[3] == 1 ) printf("C\n");*/
      printf("end\n");
   }
   if ( C[1] == 1 ) printf("A\n");
   else if ( C[2] == 1 ) printf("B\n");
   else if ( C[3] == 1 ) printf("C\n");
   return 0;
}