// cat.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


char seq[65]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-" };
char digits[11]={"0123456789"};
int DoingResult;
int IsCatCue;
unsigned char type[100];

int map(char *input)
{
	int length;
	int i,j;

	length=strlen(input);

	for (i=0;i<length;i++)
	{
		for (j=0;j<64;j++)
		{
			if (input[i]==seq[j])
			{
				break;
			}
		}
		input[i]=j;
	}

	return(0);
}

int decode(unsigned char *input, unsigned char *output)
{
	int i;
	int length=0;
	int lm;
	int output_pos=0;
	long temp;
	long li;
	int  ci;

	if (DoingResult & IsCatCue) {
		output[output_pos++]='C';
		output[output_pos++]=' ';
		li = type[2] - 32;
		ci = li / 10;
		output[output_pos++]=digits[ci];
		li = li - (ci * 10);
		output[output_pos++]=digits[li];
		}

	length=strlen(input);
	map(input);

	lm=length%4;

	if ((lm) ==1)
	{
		return(-1);
	}

	for (i=0;i<length-lm;i+=4)
	{
		/* temp=(((((( input[i] << 6) | input[i+1]) << 6) | input[i+2]) << 6 ) | input[i+3]); */
		temp = input[i];
		temp <<=6;
		temp |=input[i+1];
		temp <<=6;
		temp |=input[i+2];
		temp <<=6;
		temp |=input[i+3];

	if (DoingResult & IsCatCue) {

		li = (temp>>16) ^ 99;
		while (li > 95) li = li - 64;
		output[output_pos++]=' ';
		ci = li / 10;
		output[output_pos++]=digits[ci];
		li = li - (ci * 10);
		output[output_pos++]=digits[li];

		li = ((temp>>8) & 0xff) ^ 99;
		while (li > 95) li = li - 64;
		output[output_pos++]=' ';
		ci = li / 10;
		output[output_pos++]=digits[ci];
		li = li - (ci * 10);
		output[output_pos++]=digits[li];

		li = (temp & 0xff) ^ 99;
		while (li > 95) li = li - 64;
		output[output_pos++]=' ';
		ci = li / 10;
		output[output_pos++]=digits[ci];
		li = li - (ci * 10);
		output[output_pos++]=digits[li];

		}
	else    {

		output[output_pos++]=(temp>>16) ^ 67;
		output[output_pos++]=((temp>>8) & 0xff) ^ 67;
		output[output_pos++]=(temp & 0xff) ^ 67;

		}
}
	if (i<length)
	{
		temp = input[i];
		temp <<=6;
		temp |=input[i+1];
		temp <<=6;
		temp |=input[i+2];
		temp <<=6;
		temp |=input[i+3];
		if (lm==2)
		{
			output[output_pos++]=(temp>>16) ^67;
		}
		else
		{
			output[output_pos++]=(temp>>16) ^67;
			output[output_pos++]=((temp>>8) & 0xff) ^67;
		}

	}
	output[output_pos]='\0';
	return(0);
}

void SC_inv_case(unsigned char *input)
{
	int i,j,k;

	i=0;
	while (input[i])
	{
		if (input[i] >= 'A' && input[i] <='Z')
		{
			input[i]+=('a'-'A');
		}
		else if (input[i]>='a' && input[i]<='z')
		{
			input[i]-=('a'-'A');
		}
		i++ ;
	}
}


int main(int argc, char* argv[])
{
	unsigned char input[1000];
	unsigned char serial[1000];
	unsigned char code[1000];
	unsigned int i;

	while (fgets(input,1000,stdin)!=NULL)
	{
		if (strlen(input)<3)
		{
			break;
		}
		printf("\a");
		for (i=0;i<strlen(input);i++)
		{
			if (input[i]=='.')
			{
				break;
			}
		}
		if (input[i+1]=='c' || input[i+1]=='d' || input[i+1]=='e')
		{
			SC_inv_case(input);
		}

		DoingResult = 0;
		IsCatCue = 0;

		// skip the <alt-f10> and the leading '.'
		decode(strtok(input+i+1,"."),serial);
		decode(strtok(NULL,"."),type);

		if ( strncmp( type, "CC", 2 ) == 0 ) IsCatCue = 1;
		DoingResult = 1;
		decode(strtok(NULL,"."),code);

		printf("Serial:%s\n",serial);
		printf("Type:%s\n",type);
		printf("Code:%s\n",code);
	}
	return(0);

}

