long int form (char* num,int j)
{
     int n=0,i,w=0,l;
     l=strlen (num);
     for(i=l-1;i>=0;i--)
     {
                        if(isdigit(num[i]))
                        w=num[i]-'0';
                        else if (isalpha(num[i]))
                                 {
                                                 if(islower(num[i]))
                                                 num[i]=toupper(num[i]);
                                                 w=num[i]-'A'+10;
                                 }
                              n+=w*(int)pow(j,l-1-i);
     }
    return n;
}
int reform(long int n,char*num,int b)
{
    int y,w,i;
    for (i=0;n>=b;i++)
    {
        y=n%b;
        n=n/b;
        num[i]=y<10?'0'+y:'A'+y-10;
        }

      num[i]=n<10?'0'+n:'A'+n-10;

     return i;
     }
int main()
{
    long int n=0;
    int a,b,l,i;
    char num1[100];
    scanf("%d %s %d",&a,num1,&b);
    n=form(num1,a);
    l=reform(n,num1,b);
    for(i=l;i>=0;i--)
    {
                     printf("%c",num1[i]);
                     }
        return 0;
}


int main()
{
	int a,b,number=0;
	char num[100];
	cin>>a>>num>>b;

	if(num[0]=='0')
	{
		cout<<0;
		return 0;
	}
	for(int i=0; num[i]!='\0'; i++)
		if(num[i]>='A' && num[i]<='Z') num[i]=num[i]+32;

	for(int i=0; num[i]!='\0'; i++)
	{
		if(num[i]>='0' && num[i]<='9')
			num[i]=num[i]-48;
		else num[i]=num[i]-97+10;

		number=number*a+num[i];
	}

	char na[100];
	int i;
	for( i=0; number!=0; i++)
	{
		na[i]=number%b;
		if(na[i]>9) na[i]=na[i]+55 ;
		else na[i]=na[i]+48;
		number=number/b;
	}
	for(int j=i-1; j>=0; j--) cout<<na[j];

	return 0;
}


int zhuan1(char xx){
	int x;

	switch(xx){
		case '0':x=0;break;
		case '1':x=1;break;
		case '2':x=2;break;
		case '3':x=3;break;
		case '4':x=4;break;
		case '5':x=5;break;
		case '6':x=6;break;
		case '7':x=7;break;
		case '8':x=8;break;
		case '9':x=9;break;
		case 'a':x=10;break;
        case 'b':x=11;break;
		case 'c':x=12;break;
		case 'd':x=13;break;
		case 'e':x=14;break;
		case 'f':x=15;break;
		case 'g':x=16;break;
		case 'h':x=17;break;
		case 'i':x=18;break;
		case 'j':x=19;break;
		case 'k':x=20;break;
		case 'l':x=21;break;
		case 'm':x=22;break;
		case 'n':x=23;break;
		case 'o':x=24;break;
		case 'p':x=25;break;
		case 'q':x=26;break;
		case 'r':x=27;break;
		case 's':x=28;break;
		case 't':x=29;break;
		case 'u':x=30;break;
		case 'v':x=31;break;
		case 'w':x=32;break;
		case 'x':x=33;break;
		case 'y':x=34;break;
		case 'z':x=35;break;
        case 'A':x=10;break;
        case 'B':x=11;break;
		case 'C':x=12;break;
		case 'D':x=13;break;
		case 'E':x=14;break;
		case 'F':x=15;break;
		case 'G':x=16;break;
		case 'H':x=17;break;
		case 'I':x=18;break;
		case 'J':x=19;break;
		case 'K':x=20;break;
		case 'L':x=21;break;
		case 'M':x=22;break;
		case 'N':x=23;break;
		case 'O':x=24;break;
		case 'P':x=25;break;
		case 'Q':x=26;break;
		case 'R':x=27;break;
		case 'S':x=28;break;
		case 'T':x=29;break;
		case 'U':x=30;break;
		case 'V':x=31;break;
		case 'W':x=32;break;
		case 'X':x=33;break;
		case 'Y':x=34;break;
		case 'Z':x=35;break;
}
	return x;
}
char zhuan2(int yy){
	char tt;
switch(yy){
        case 0:tt='0';break;
		case 1:tt='1';break;
		case 2:tt='2';break;
		case 3:tt='3';break;
		case 4:tt='4';break;
		case 5:tt='5';break;
		case 6:tt='6';break;
		case 7:tt='7';break;
		case 8:tt='8';break;
		case 9:tt='9';break;
        case 10:tt='A';break;
        case 11:tt='B';break;
		case 12:tt='C';break;
		case 13:tt='D';break;
		case 14:tt='E';break;
		case 15:tt='F';break;
		case 16:tt='G';break;
		case 17:tt='H';break;
		case 18:tt='I';break;
		case 19:tt='J';break;
		case 20:tt='K';break;
		case 21:tt='L';break;
		case 22:tt='M';break;
		case 23:tt='N';break;
		case 24:tt='O';break;
		case 25:tt='P';break;
		case 26:tt='Q';break;
		case 27:tt='R';break;
		case 28:tt='S';break;
		case 29:tt='T';break;
		case 30:tt='U';break;
		case 31:tt='V';break;
		case 32:tt='W';break;
		case 33:tt='X';break;
		case 34:tt='Y';break;
		case 35:tt='Z';break;
		}
return tt;
}
int main(int argc, char* argv[])
{
	int n,m,x,k,i,j,count,y=0;
	char str[10];

	char str1[100];

	scanf("%d",&n);
	scanf("%s",str);
	scanf("%d",&m);
	count=strlen(str);

	for(i=0;i<=count-1;i++){
	x=zhuan1(str[i]);
		y=y+(x*(int)pow(n,count-1-i));

	}
	if(y==0){
		printf("0");
	return 0;
	}

	int count1=0;
	for(k=0,j=0;y!=0;k++,j++){

	str1[j]=zhuan2(y%m);
		y=y/m;
		count1++;
	}
	for(j=count1-1;j>=0;j--){

		printf("%c",str1[j]);
	}

	return 0;
}


long trans1(char *s,int n)
{
	long ans=0;
	int i,j,len;
	len=strlen(s);
	for(i=0;i<len;i++)
	{
		if(s[i]>='0'&&s[i]<='9')
		{
			j=s[i]-'0';
			ans=ans+j*pow(n,len-i-1);
		}
		else if(s[i]>='a'&&s[i]<='z')
		{
			j=s[i]-'a'+10;
			ans=ans+j*pow(n,len-i-1);
		}
		else if(s[i]>='A'&&s[i]<='Z')
		{
			j=s[i]-'A'+10;
			ans=ans+j*pow(n,len-i-1);
		}
	}
	return ans;
}
void trans2(char *s,int n,long m)
{
	int i,r,len;
	for(i=0;m!=0;i++)
	{
		r=m%n;
		if(r>=10)
			s[i]=r-10+'A';
		else
			s[i]=r+'0';
		m=m/n;
	}
	s[i]='\0';
	len=strlen(s);
	for(i=len-1;i>=0;i--)
		putchar(s[i]);
}
void main()
{
	int n1,n2;
	long k;
	char s[5000],ans[5000];
	scanf("%d%s%d",&n1,s,&n2);
	if(s[0]=='0')
		printf("0");
	else
	{
		k=trans1(s,n1);
		trans2(ans,n2,k);
	}
}


void main()
{
	int from,to;
	char num[33],result[33]={0};
	long dec=0;
	int i,j;
	scanf("%d%s%d",&from,num,&to);
    if (num[0]=='0') printf("0");
	else
	{
		//??10??
		for(i=0;i<strlen(num);i++)
		{
			dec*=from;
			if (num[i]>='0' && num[i]<='9')
				dec=dec+num[i]-'0';
			else if (num[i]>='A' && num[i]<='Z')
				dec=dec+num[i]-'A'+10;
			else if (num[i]>='a' && num[i]<='z')
				dec=dec+num[i]-'a'+10;
		}
		//??????
		if (to==10)
			printf("%d",dec);
		else
		{
			int digit;
			i=0;
			while(dec!=0)
			{
				digit=dec%to;
				if (digit>=0 && digit<=9)
					result[i]=digit+'0';
				else
					result[i]=digit-10 +'A';
				i++;
				dec=(dec-digit)/to;
			}
			//????
			for(j=strlen(result)-1;j>=0;j--)
				putchar(result[j]);

		}
	}
}


int zh(char a)
{
	int b;
	if((a>='A')&&(a<='Z'))
	{
		b=(int)(a)-55;
		return b;
	}
	else
	{
		b=(int)(a)-48;
		return b;
	}
}
char fzh(int a)
{
	char b;
	if(a>9)
	{
		b=(char)(a+55);
		return b;
	}
	else
	{
		b=(char)(a+48);
		return b;
	}
}
int cf(int a,int b)
{
	int i;
	int sum=a;
	if(b==0)
	{
		sum=1;
	}
	for(i=0;i<b-1;i++)
	{
		sum*=a;
	}
	return sum;
}
int main()
{
	int a,b;
	int i,j;
	int l;

	char c[10000];
	char t[10000];
	int sum=0;

	scanf("%d%s%d",&a,c,&b);
	l=strlen(c);
	for(i=0;i<l;i++)
	{
		if((c[i]>='a')&&(c[i]<='z'))
	{
			c[i]=c[i]-'a'+'A';
		}
	}

	for(i=0;i<l;i++)
	{
		sum+=cf(a,l-1-i)*zh(c[i]);
	}

	if(sum==0)
	{
	printf("0");
	}

	for(i=0;sum!=0;i++)
	{
		t[i]=fzh(sum%b);
		sum=sum/b;
	}

	for(j=i-1;j>=0;j--)
	{
		printf("%c",t[j]);
	}

	printf("\n");

	return 0;
}


int zheng(char x);
char fan(int x);
int main(){
	int n,m,f,sum,i;
	char zhuan[50];
	scanf("%d",&n);
	char x[10];
	scanf("%s",x);
	scanf("%d",&m);
	f=strlen(x);
	sum=0;
	int wei=0;
	for(i=0;i<f;i++){
		sum=sum+zheng(x[i])*pow(n,f-i-1);
	}
	for(i=49;i>=0;i--){
		zhuan[i]=fan(sum%m);
		wei++;
		sum=sum/m;
		if(sum==0)
			break;
	}
	for(i=50-wei;i<50;i++){
		printf("%c",zhuan[i]);
	}
  return 0;
}

int zheng(char x){
int m;
   switch(x){
case '1':m=1;break;
case '2':m=2;break;
case '3':m=3;break;
case '4':m=4;break;
	case '5':m=5;break;
	case '6':m=6;break;
	case '7':m=7;break;
	case '8':m=8;break;
	case '9':m=9;break;
	case '0':m=0;break;
	case 'a':m=10;break;
	case 'A':m=10;break;
	case 'b':m=11;break;
	case 'B':m=11;break;
case 'c':m=12;break;
case 'd':m=13;break;
	case 'e':m=14;break;
	case 'f':m=15;break;
	case 'g':m=16;break;
	case 'h':m=17;break;
case 'i':m=18;break;
	case 'j':m=19;break;
	case 'k':m=20;break;
	case 'l':m=21;break;
	case 'm':m=22;break;
	case 'n':m=23;break;
	case 'o':m=24;break;
	case 'p':m=25;break;
	case 'q':m=26;break;
	case 'r':m=27;break;
	case 's':m=28;break;
	case 't':m=29;break;
	case 'u':m=30;break;
	case 'v':m=31;break;
	case 'w':m=32;break;
	case 'x':m=33;break;
	case 'y':m=34;break;
	case 'z':m=35;break;
	case 'C':m=12;break;
	case 'D':m=13;break;
	case 'E':m=14;break;
	case 'F':m=15;break;
	case 'G':m=16;break;
	case 'H':m=17;break;
	case 'I':m=18;break;
	case 'J':m=19;break;
	case 'K':m=20;break;
	case 'L':m=21;break;
	case 'M':m=22;break;
	case 'N':m=23;break;
	case 'O':m=24;break;
	case 'P':m=25;break;
	case 'Q':m=26;break;
	case 'R':m=27;break;
	case 'S':m=28;break;
	case 'T':m=29;break;
	case 'U':m=30;break;
	case 'V':m=31;break;
case 'W':m=32;break;
	case 'X':m=33;break;
	case 'Y':m=34;break;
	case 'Z':m=35;break;

   }
   return m;
}

char fan(int x){
	char m;
	switch(x){
	case 0:m='0';break;
	case 1:m='1';break;
	case 2:m='2';break;
	case 3:m='3';break;
	case 4:m='4';break;
	case 5:m='5';break;
	case 6:m='6';break;
	case 7:m='7';break;
	case 8:m='8';break;
	case 9:m='9';break;
	case 10:m='A';break;
	case 11:m='B';break;
	case 12:m='C';break;
	case 13:m='D';break;
	case 14:m='E';break;
	case 15:m='F';break;
	case 16:m='G';break;
	case 17:m='H';break;
	case 18:m='I';break;
	case 19:m='J';break;
	case 20:m='K';break;
	case 21:m='L';break;
	case 22:m='M';break;
	case 23:m='N';break;
	case 24:m='O';break;
	case 25:m='P';break;
	case 26:m='Q';break;
	case 27:m='R';break;
	case 28:m='S';break;
	case 29:m='T';break;
	case 30:m='U';break;
	case 31:m='V';break;
	case 32:m='W';break;
	case 33:m='X';break;
	case 34:m='Y';break;
	case 35:m='Z';break;

	}
	return m;
}


void main()
{
char intonumber(char x);
char intochar(int y);
char str[N];
gets(str);

int i=0,c1=0;
while(str[i]!=' ')
{
	c1=c1*10+intonumber(str[i++]);
}
while(str[i]==' ')
	i++;

unsigned long n1=0;
while(str[i]!=' ')
{
	n1=n1*c1+intonumber(str[i++]);

}
while(str[i]==' ')
	i++;

int l1=0;
while(str[i]!='\0')
{
l1=l1*10+intonumber(str[i++]);
}

int f;
char yu[M];
for(f=0;n1>0;f++)
{
	yu[f]=intochar(n1%l1);
	n1=n1/l1;
}
if (f==0) printf("%d",0);
for(f--;f>=0;f--)
printf("%c",yu[f]);

}

char intonumber(char x)
{
	if(x>='a'&&x<='z')
		x=x-87;
	else if(x>='A'&&x<='Z')
		x=x-55;
	else if(x>=48&&x<=57)
		x=x-48;
	return(x);
}

char intochar(int y)
{
	if(y>=0&&y<=9)
		y=y+48;
	else if(y>9&&y<=35)
		y=y+55;
	return(y);

}


int xToTen(int x, char c[])
{
	int i, lenth, ten, num;
	lenth = strlen(c);
	for(i = 0, ten = 0; i < lenth; i++)
	{
		if(c[i] >= '0' && c[i] <= '9')
			num = c[i] - '0';
		if(c[i] >= 'A' && c[i] <= 'Z')
			num = c[i] - 'A' + 10;
		if(c[i] >= 'a' && c[i] <= 'z')
			num = c[i] - 'a' + 10;
		ten = ten * x + num;
	}
	return (ten);
}

void tenToYout(int ten, int y)
{
	int a[100];
	int i, lenth;
	for(lenth = 0; ten >= y; lenth++)
	{
		a[lenth] = ten % y;
		ten /= y;
	}
	a[lenth] = ten;
	for(i = lenth; i >= 0; i--)
	{
		if(a[i] < 10)
			cout << a[i];
		else
			cout << (char)(a[i] - 10 + 'A');
	}
	cout << endl;
}

int main()
{
	char c[100];
	int x, y;
	cin >> x >> c >> y;
	tenToYout (xToTen(x, c), y);
	return 0;
}


void shuchu(int c[], int i)
{
	int j;
	for(j = i - 1 ; j >= 0 ; j--)
	{
		if(c[j] >= 0 && c[j] <= 9)
		{
			cout << c[j];
		}
		if(c[j] >= 10)
		{
			cout << (char)(c[j] + 55);
		}
	}
	cout << endl;
}
int main()
{
	char str1[10000], str2[10000], l;
	int i, j, num[10000] = {0}, sum = 0, c[10000] = {0}, nlen, k;
	double  before , after;
	memset(str1, ' ', sizeof(str1));
	memset(str2, ' ', sizeof(str2));
	cin >> before;
	cin >> str1;
	cin >> after;
	nlen = strlen(str1);
	for(i = 0 ; i < nlen ; i++)
	{
		if(str1[i] >= 97 && str1[i] < 122)
		{
			str1[i] = (char)toupper(str1[i]);
		}
		if(str1[i] >= 65 && str1[i] <= 90)
		{
			num[i] = str1[i] - '7';
		}
		else
			num[i] = str1[i] - '0';
	}
	k = nlen - 1;
	for(i = 0 ; i < nlen ; i++)
	{

		sum = sum + num[i] * pow(before, k);
		k--;
	}
	i = 0;
	do
	{
		c[i] = sum % (int)after;

		sum = sum / after;
		i++;
	}while(sum > 0);
	shuchu(c, i);

	return 0;
}


int power(int,int);
int main ()
{
	char number1[100],number2[100];
	int i,first,second,ten=0,l1,l2=0,remain;
	cin >> first ;
	cin.get();
	cin.getline(number1,100,' ');
	cin >> second;
	l1=strlen(number1);
	for (i=0;i<l1;i++)
	{
		if (number1[i]>='a'&&number1[i]<='z')
			ten=(number1[i]-'a'+10)*(int)(power(first,l1-i-1))+ten;
		if (number1[i]>='A'&&number1[i]<='Z')
			ten=(number1[i]-'A'+10)*(int)(power(first,l1-i-1))+ten;
		if (number1[i]>='0'&&number1[i]<='9')
			ten=(number1[i]-'0')*(int)(power(first,l1-i-1))+ten;
	}                                        //??????
	remain=ten;
	while (remain!=0)
	{
		remain=remain/second;
		l2++;
	}
	if (ten==0)
		l2=1;
	for (i=0;i<l2;i++)
	{
		number2[i]=ten/(int)(power(second,l2-i-1));
		ten=ten-number2[i]*(int)(power(second,l2-i-1));
		if (number2[i]>=10)
			number2[i]=number2[i]-10+'A';
		else
			number2[i]=number2[i]+'0';
	}
	number2[l2]='\0';
	cout << number2 << endl;
	return 0;
}
int power(int a,int b)
{
	int i,sum = 1;
	for(i = 1; i <= b; i++)
		sum = sum * a;
	return sum;
}


void main()
{
char num[50];
int answer=0,i,j,a,b,n,an[50];
scanf("%d%s%d",&a,num,&b);

n=strlen(num);
for(i=0;i<n;i++)
{
if(num[i]>47&&num[i]<58)
answer=answer+(num[i]-48)*pow(a,n-i-1);
if(num[i]>64&&num[i]<91)
answer=answer+(num[i]-55)*pow(a,n-i-1);
if(num[i]>96&&num[i]<123)
answer=answer+(num[i]-87)*pow(a,n-i-1);
}

for(j=0;;j++)
{
i=answer%b;
answer=(answer-i)/b;
if(i>=0&&i<10)
an[j]=i+48;
if(i>=10)
an[j]=i+55;
if(answer==0)
break;

}
for(i=j;i>=0;i--)
printf("%c",an[i]);
}


int main(int argc, char* argv[])
{
	unsigned int a,b,n;
	char num[100]={0};
	cin>>a>>num>>b;

	int i;
	unsigned int s=0;
	n=strlen(num);//?????
	for(i=0;i<n;i++)
	{
		if(num[i]>='a')
			num[i]=num[i]-87;
		else if(num[i]>='A')
			num[i]=num[i]-55;
		else
		{
		    num[i]=num[i]-48;
		}
		s=(int)(s+num[i]*pow((double)a,(double)(n-i-1)));//??
	}
	//cout<<s<<endl;
	char m[100];
	int j=0;
	for(j=0;s>0;j++)
	{
		  m[j]=s%b;
		  s=s/b;
          if(m[j]>9)
			  m[j]=m[j]+55;
		  else
			  m[j]=m[j]+48;
	}
	if(j == 0 )
		cout<<0;
	else
	for(j=j-1;j>=0;j--)
		cout<<m[j];

		  return 0;
}


//????a?
long long nta(long long a)
{
	if(a>=10)
	{
	char b;
	b=(char)('A'-10+a);
	return ((char) (b));
	}
	else
	{
	char b;
	b=(char)('1'-1+a);
	return ((char) (b));
	}
}
//a????
long long atn(char i)
{
	long long j=i;
	if(j>96)
	{
		j=j-'a'+10;
	}
	else
	{   if ((j>33)&&(j<58))
	{
		j=j-'1'+1;
	}
	else
	{
		j=j-'A'+10;
	}
	}
	return((long long)(j));
}
//???????
long long ten(long long k)
{
	long long l,m;
	l=k;
	for (long long n = 0; n < 69; n++)
	{
		l=l/10;
		if (l>0)
		{
			m=n+1;
		}
	}
	return (m);
}
//??e??
long long loe(long long t,long long v)
{
	long long u,w=0;
	u=t;
	for (long long x = 0; x < 69; x++)
	{
		u=u/v;
		if (u>0)
		{
			w=x+1;
		}
	}
	return (w);
}
//??????
long long lth(char o[])
{
	long long f=0;
	for (long long g = 0; g <69 ; g++)
	{
		if((o[g]!=0)&&(o[g]!=32))f=f+1;
	}
	return ((f));
}
int main()
{
	long long d,e;
	char h[70];
	memset(h,0,sizeof(h));
	cin>>d>>h>>e;
	long long p;
	p=lth(h);
	long long s=0;
	long long ae[100];
	ae[0]=1;
	for (long long af= 1;  af< 20; af++)
	{
		ae[af]=ae[af-1]*d;
	}
	for (long long q = p-1; q >=0 ; q--)
	{
		s=s+(atn(h[q])*ae[p-1-q]);
	}

	long long y;
	y=(loe(s,e));
	char aa[70];
	memset(aa,0,sizeof(aa));
	long long ab=s,ac=0;
	for (long long z = 0; z < y+1; z++)
	{
		ac=ab;
		ab=ab/e;
		if (ab>0)
		{
			aa[z]=nta(ac%e);
		}
		else
		{
			aa[z]=nta(ac);
		}

	}

	for (long long ad = 0; ad < y+1; ad++)
	{
		cout<<aa[y-ad];
	}

	return 0;
}


int main()
{
int n,a,b,i,k=-1,dec=0,temp[33];
char num[33],result[33];
cin>>a>>num>>b;
n=strlen(num);
for(i=0;i<n;i++)
{
if(num[i]>='A'&&num[i]<='Z')
num[i]=num[i]+'a'-'A';
}
for(i=0;i<n;i++)
{
    if(num[i]>='a'&&num[i]<='z')
dec=dec*a+(num[i]-'a'+10);
else
dec=dec*a+(num[i]-'0');
}
if(dec==0)
cout<<'0'<<endl;
else
while(dec>0)
{
k=k+1;
temp[k]=dec%b;
dec=(dec-dec%b)/b;
}
for(i=k;i>=0;i--)
{
if(temp[i]<10)
result[i]=temp[i]+'0';
else
result[i]=temp[i]+'A'-10;
cout<<result[i];
}
cout<<endl;
return 0;
}


void main()
{
	int a,b,i,expa,expb;
	long temp=0;
	char r[65];
	char n[65]={0};
	scanf("%d %s %d",&a,n,&b);
	expa=strlen(n);
	for(i=0;n[i]!='\0';i++)
	{
		if(n[i]>='a') n[i]+=-87;
		else if(n[i]>='A') n[i]+=-55;
		else n[i]+=-48;
		temp+=n[i]*(int)pow(a,expa-1-i);
	}
	if(temp==0)
		printf("0");
	else
	{
		expb=(int)(log(temp)/log(b))+1;
		for(i=0;i<expb;i++)
		{
			r[i]=(temp%(int)(pow(b,expb-i)))/(int)pow(b,expb-1-i);
			if(r[i]>=10) r[i]+=55;
			else r[i]+=48;
			printf("%c",r[i]);
		}
	}
printf("\n");
}


int main()
{
	int f(char x);
	char x[100],z[100],w;
	int y[100];
	int a,b,c,d,j,k,sum=0,i,t=0;
	scanf("%d",&a);
	scanf("%s",x);
	scanf("%d",&b);
	c=strlen(x);
	for(i=c-1;i>=0;i--)
	{
		y[i]=f(x[i]);
		sum+=(int)(y[i]*pow(a,c-i-1));
	}
	if(sum==0)
		printf("0");
	else
	{
		for(i=1;i<=1000;i++)
		{
			if(sum<pow(b,i))
				{
					d=i-1;
					break;
				}
		}
	for(j=d;j>=0;j--)
	{
		for(k=1;k<=b;k++)
		{
			if(sum>=k*pow(b,j))
				continue;
			else
			{
				if(k<11)
					w=k+47;
				else
					w=k+54;
				z[t]=w;
				sum-=(int)((k-1)*pow(b,j));
				t=t+1;
				break;
			}
		}
	}
	for(i=0;i<t;i++)
	{
		printf("%c",z[i]);
	}
	printf("\n");
	}
	return 0;
}
int f(char x)
{
	if(islower(x))
		return x-87;
	else
		if(isupper(x))
			return x-55;
		else
			return x-48;
}


int ston(char x[],int y,int);
void ntos(char x[],int y,int z);
void main()
{
		char in[100]="\0",out[100]="\0";
		int i,d,exp1,exp2,l;

		scanf("%d %s %d",&exp1,in,&exp2);
		l=strlen(in);
		for(i=0;i<l;i++)
                      if(in[i]<='z'&&in[i]>='a')in[i]=in[i]+'A'-'a';

		d=ston(in,exp1,l);
		ntos(out,exp2,d);
		for (i=0;i<=strlen(out)-1;i++)
		{
				if(out[i]>=10+'0')out[i]=out[i]+'A'-10-'0';
		}
		puts(out);
}
int ston(char x[],int y,int l)
{
	int z=0;
	int i;
	for(i=0;i<l;i++)
			{
					if(*(x+i)<='Z'&&*(x+i)>='A')x[i]=x[i]-'A'+10;
					else *(x+i)=*(x+i)-'0';
			}
	for(i=1;i<=l;i++)
	{

			z=z*y+x[i-1];
	}
	return(z);
}
void ntos(char x[],int y,int z)
{
		if(z<y)x[0]=z+'0';
		else
		{
				ntos(x,y,z/y);
				x[strlen(x)]=z%y+'0';
		}
}


char str[50],ans[50];
int main()
{
	int i,j,k,l,length,num,x;
	long m,n,ten=0,ten2=0;
	scanf("%ld%s%ld",&n,str,&m);
	length=strlen(str);
	for(i=0;i<length;i++)
	{
		x=1;
		if((str[i]>='a')&&(str[i]<='z')) num=str[i]-87;
		else if((str[i]>='A')&&(str[i]<='Z')) num=str[i]-55;
		else num=str[i]-48;
		for(j=0;j<(length-i-1);j++)
		{
			x=x*n;
		}
		ten=ten+x*num;
	}
	if(ten==0) printf("0\n");
	else
	{
		for(k=0;(ten!=0);k++)
		{
			ten2=ten;
			ten=ten/m;
			ans[k]=ten2-ten*m+48;
		}
		for(l=0;l<k;l++)
		{
			if(l!=(k-1))
			{
				if(ans[k-l-1]>'9') {ans[k-l-1]=ans[k-l-1]+7;printf("%c",ans[k-l-1]);}
				else printf("%c",ans[k-l-1]);
			}
			else
			{
				if(ans[k-l-1]>'9') {ans[k-l-1]=ans[k-l-1]+7;printf("%c\n",ans[k-l-1]);}
				else printf("%c\n",ans[k-l-1]);
			}
		}
	}
	return 0;
}


int b;
void main()
{   void PF(int k);
	int a; char n[10];int i,len;

	scanf("%d %s %d",&a,n,&b);
	len=strlen(n);
	int sum=0;
	for(i=0;i<len;i++)
	{
		if(n[i]>='0'&&n[i]<='9')
			sum=sum*a+n[i]-'0';
		else
                    if(n[i]>='a'&&n[i]<='z')
                    sum=sum*a+n[i]-'a'+10;
                else
                     sum=sum*a+n[i]-'A'+10;
	}
	PF(sum);
}

	void PF(int k)
	{
		if(k<b)
		{
			if(k>=0&&k<=9)
				printf("%c",k+'0');
			else
				printf("%c",k-10+'A');
		}
		else
		{
			PF(k/b);
				if(k%b>=0&&k%b<=9)
				printf("%c",k%b+'0');
			else
				printf("%c",k%b-10+'A');
		}
	}


int main()
{
	long mizhi(int input1,int input2);
	long a,b,temp,temp1=0,temp2,temp3;
	int n,i,j,k=0;
	char str[1000];
	scanf("%d%s%d",&a,&str,&b);
	n=strlen(str);
	for(i=0;i<n;i++)
	{
		if(str[i]>=65&&str[i]<=90)
		{
			temp2=str[i]-55;
		}
		else if(str[i]>=97&&str[i]<=122)
		{
			temp2=str[i]-87;
		}
		else if(str[i]>=48&&str[i]<=57)
		{
			temp2=str[i]-48;
		}
		temp1=temp1+temp2*mizhi(a,n-1-i);
	}
	temp=temp1;
	for(j=0;;j++)
	{
		if(temp<b)
		{
			break;
		}
		else
		{
			temp=temp/b;
			k++;
		}
	}
	for(i=0;i<=k;i++)
	{
		if(temp1>=b)
		{
			if(temp1/mizhi(b,k-i)<=9)
			{
		printf("%ld",temp1/mizhi(b,k-i));
		temp1=temp1%mizhi(b,k-i);
			}
			else
			{
			printf("%c",55+temp1/mizhi(b,k-i));
		temp1=temp1%mizhi(b,k-i);
			}
		}
		else if(temp1<b&&k-i!=0)
		{
			printf("0");
		}
		else
		{
			if(temp1<=9)
			{
		printf("%ld",temp1);
			}
			else
			{
			printf("%c",55+temp1);
			}
			break;
		}
	}
}

long mizhi(int input1,int input2)
{
	int z=1,k=1;
	if(input2==0)
	{
		return(1);
	}
	else
	{
	do
	{
		z=z*input1;
		k++;
	}while(k<=input2);
	}
	return(z);
}


void up(char *input)
{
	while (*input)
	{
		if (((*input)>='a')&&((*input)<='z')) *input-=32;
		input++;
	}
}

int main()
{
	char chart[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int src=0,dst=0;

	int i;
	long int result=0;
	char input[100],output[MAX],*curr;

	scanf("%d %s %d",&src,input,&dst);

	up(input);
	for(i=0;input[i];i++)
	{
		if (input[i]>='A')
			result=result*src+input[i]-'A'+10;
		else result=result*src+input[i]-'0';
	}
	output[MAX-1]=0;
	curr=&(output[MAX-1]);
	do
	{
		curr--;
		*curr=chart[result%dst];
		result/=dst;
	}while (result);
	printf("%s",curr);
	return 0;
}


int main(int argc, char* argv[])
{
	char a[3],b[100],c[3],after[100],strtmp,after1[100];
	int before=0 ;
	int n1,n2,i,n,A[100],tmp,m;
	scanf ("%s %s %s",a,b,c);
    n1=atoi (a);
	n2=atoi (c);
	n=strlen (b);
    //printf ("%d\n%d\n",n1,n2);
    for (i=0;i<n;i++)
	{
		if (b[i]>='a'&&b[i]<='z')
			b[i]=b[i]-32;
		if (b[i]>='0'&&b[i]<='9')
			A[i]=b[i]-48;
		if (b[i]>='A'&&b[i]<='Z')
			A[i]=b[i]-55;
		//printf ("%d\n",A[i]);
	}

    for (i=0;i<n;i++)
	{
         before = before*n1+A[i];
	}//printf ("%d\n",before);
	if (before==0)
	{after1[0]='0';after1[1]='\0';}
	else {
	for (i=0;i<100;i++)
	{
		if (before<1)
			break;
		else
		{
            tmp=before%n2;
			before=before/n2;
			if(tmp>=10)
               strtmp=tmp+55;
			else
			   strtmp=tmp+48;
			after[i]=strtmp;
		}
	}
	after[i]='\0';
	//puts (after);
	m=strlen (after);
	//printf ("%d\n",m);
    for (i=0;i<m;i++)
	{
         after1[i]=after[m-i-1];
	}
	after1[i]='\0';}
	puts (after1);
	return 0;
}


char CHR[120];
int p1,p2,p3,num;

int deal(char Q)
{
	if ((Q>='0')&&(Q<='9')) return Q-'0';
	if ((Q>='A')&&(Q<='Z')) return Q-'A'+10;
	return -1;
}
char laed(int Q)
{
	if ((Q>=0)&&(Q<=9)) return '0'+Q;
	if (Q>9) return 'A'+Q-10;
}
void output(int ans)
{
	if (ans==0) return;
	else
	{
		output(ans/p3);
		cout<<laed(ans%p3);
	}
}
int main()
{
	cin>>p1;cin.get();
	p2=0;num=0;
	while ((CHR[p2]=cin.get())!=' ')
	{
		if ((CHR[p2]>='a')&&(CHR[p2]<='z')) CHR[p2]=CHR[p2]-'a'+'A';
		num=num*p1+deal(CHR[p2]);
		p2++;
	}
	cin>>p3;
	if (num==0) cout<<0;
	else output(num);
	cout<<endl;
	return 0;
}


int main()
{
int a=0,b=0,length=0;
long long dec = 0;
char origin[100],final[100];            //???char origin?a???~int temp?a???~dec?????~int answer?b???~char final?b???
int temp[100]={0},answer[100]={0};
cin>>a>>origin>>b;

length=strlen(origin);

for(int i=length-1;i>=0;i--)          //char origin?a???~int temp?a???
   {
  if(origin[i]>='a'&&origin[i]<='z')
            temp[i]=origin[i]-87;
  else if(origin[i]>='A'&&origin[i]<='Z')
       temp[i]=origin[i]-55;
  else
   temp[i]=origin[i]-48;
    }

for(int i=length-1;i>=0;i--)       //int temp?a???~dec?????
  {

 dec=dec+temp[i]*pow((double)a,(length-i-1));

  }
//cout<<dec;

int j=0;
   while((dec/b)!=0)            //dec?????~int answer?b????????
    {
        answer[j]=dec%b;
   dec=dec/b;
j++;
    }
   answer[j]=dec%b;

  for(int k=j;k>=0;k--)           //int answer?b???~char final?b??????????
  {
      if(answer[k]>=10&&answer[k]<=35)
 {
 final[k]=(char)(answer[k]+55);
 cout<<final[k];
      }
 else
 cout<<answer[k];

  }

}


void main()
{
	char n[20],tab[100];
	int a,b,nlen,k,z[10];
	long d=0,i;
	scanf("%d%s%d",&a,n,&b);
     nlen=strlen(n);
    for(i=0;i<nlen;i++)
	  {
		if(n[i]>='0'&&n[i]<='9')
			z[i]=n[i]-48;
		else
			if(n[i]>='a'&&n[i]<='z')
				z[i]=n[i]-87;
	    else
			if(n[i]>='A'&&n[i]<='Z')
				z[i]=n[i]-55;
	  }

	   for(i=0;i<nlen;i++)
	   {
        k=pow(a,nlen-i-1);
		d=d+z[i]*k;
	   }
	   if(d==0)
		   printf("0");
	   else
	   {
       for(i=0;i<36;i++)
	   {
          if(d%b<=9)
            tab[i]=d%b;
            switch(d%b)
			{
                 case 10:tab[i]='A';break;
                 case 11:tab[i]='B';break;
                 case 12:tab[i]='C';break;
                 case 13:tab[i]='D';break;
                 case 14:tab[i]='E';break;
                 case 15:tab[i]='F';break;
                 case 16:tab[i]='G';break;
                 case 17:tab[i]='H';break;
                 case 18:tab[i]='I';break;
                 case 19:tab[i]='J';break;
                 case 20:tab[i]='K';break;
                 case 21:tab[i]='L';break;
                 case 22:tab[i]='M';break;
                 case 23:tab[i]='N';break;
                 case 24:tab[i]='O';break;
                 case 25:tab[i]='P';break;
                 case 26:tab[i]='Q';break;
                 case 27:tab[i]='R';break;
                 case 28:tab[i]='S';break;
                 case 29:tab[i]='T';break;
                 case 30:tab[i]='U';break;
                 case 31:tab[i]='V';break;
                 case 32:tab[i]='W';break;
                 case 33:tab[i]='X';break;
                 case 34:tab[i]='Y';break;
                 case 35:tab[i]='Z';break;
			}

           d/=b;
	   }
      for(i=35;i>=0;i--)
         if(tab[i]!=0)
          break;

      for(;i>=0;i--)
	  {
       if(tab[i]>9)
       printf("%c",tab[i]);
         else
      printf("%d",tab[i]);
	  }
	   }
}


void preProcess(char *p)
{
	for (int i = 0; i < strlen(p); i++)
	{
		if (*(p + i) - 'a' >= 0 && *(p + i) - 'z' <= 0)
		{
			*(p + i) = '0' + (*(p + i) - 'a' + 10);
			continue;
		}
		if (*(p + i) - 'A' >= 0 && *(p + i) - 'Z' <= 0)
		{
			*(p + i) = '0' + (*(p + i) - 'A' + 10);
			continue;
		}
	}
}

int main()
{
	int m, n;
	char sOrig[200], sRes[200];

	cin >> m >> sOrig >> n;

	preProcess(sOrig);

	//cout << sOrig << endl;

	int nValue = 0;

	char *p = sOrig;
	while (*p != '\0')	nValue = nValue * m + *p++ - '0';

	char *s = sRes;
	if (nValue == 0)
	{
		*s++ = '0';
	}
	while (nValue)
	{
		if (nValue % n < 10)	*s++ = nValue % n + '0';
		else	*s++ = nValue % n - 10 + 'A';
		nValue /= n;
	}
	*s-- = '\0';

	while(s >= sRes)	cout << *s--;
	cout << endl;

	return 0;
}


int main()
{
	long convert_to10(char str[], int a);
	void convert_from10(long a, int b);
	int a, b;
	char str[100];
	cin >> a >> str >> b;

	convert_from10(convert_to10(str, a), b);
	return 0;

}

long convert_to10(char str[], int a)
{
	int len, i;
	long num10 = 0;
	len = strlen(str);
	for (i = 0; i < len; i++)
	{
		if (str[i] >= 'A' && str[i] <= 'Z')
			num10 = num10 * a + str[i] - 'A' + 10;
		if (str[i] >= 'a' && str[i] <= 'z')
			num10 = num10 * a + str[i] - 'a' + 10;
		if (str[i] >= '0' && str[i] <= '9')
			num10 = num10 * a + str[i] - '0';
	}
	return num10;
}

void convert_from10(long a, int b)
{
	char str[10000];
	int i, j, k, len;
	for (i = 0;;i++)
	{
		k = a % b;
		if (k < 10)
			str[i] = k + '0';
		else
			str[i] = k - 10 + 'A';
	    a = (a - k) / b;
		len = i;

		if (a == 0)
		{
			for (j = len; j >= 0; j--)
				cout << str[j];
			break;
		}

	}
}


int main(){
	int i,j;
	int a,b;
	long mid=0;
	char out[100];
	cin>>a;

	cin.get();
	char tempC;
	int temp;
	while((tempC = cin.get()) != ' '){

		if(tempC>='0' && tempC<='9')
			temp = tempC-'0';
		else if(tempC>='a' && tempC<='z')
			temp = tempC-'a'+10;
		else if(tempC>='A' && tempC<='Z')
			temp = tempC-'A'+10;
		mid *= a;
		mid += temp;
	}

	cin>>b;
	i = 0;
	while(mid > 0){
		temp = mid%b;
		if(temp >9){
			tempC = temp-10+'A';
		}
		else{
			tempC = temp+'0';
		}
		out[i]=tempC;
		++i;
		mid /= b;
	}
	if(i==0)
		cout<<"0"<<endl;
	else{
		for(j = i-1;j>=0;--j){
			cout<<out[j];
		}
		cout<<endl;
	}
	cin>>a;
	return 0;
}


int main()

{

    char input[100],output[100];

    int number[100],remainder[100],sum=0,a,b,i,t,l,g=1;

    scanf("%d %s %d",&a,input,&b);
	l=strlen(input);

    for(i=0;i<l;i++)

  {

   if(input[i]>='A' && input[i]<='Z')

      number[i]=input[i]-'A'+10;

   if(input[i]>='a' && input[i]<='z')

      number[i]=input[i]-'a'+10;

   if(input[i]>='0' && input[i]<='9')

      number[i]=input[i]-'0';

}
	for (i=0;i<l;i++)
	{
		g=1;
		for (t=0;t<i;t++)
		{
			g*=a;
		}
		 sum=sum+number[l-1-i]*g;
	}

for(i=0;i<100;i++)

{

                  remainder[i]=sum%b;

                  if(sum/b==0)

                       break;

                 sum=sum/b;

}
  t=i+1;

  for(i=t-1;i>=0; i--)

{

       if(remainder[i]>=0 && remainder[i]<=9)

    output[t-i-1]=       remainder[i]+'0';

    if(remainder[i]>=10 && remainder[i]<=35)

    output[t-i-1]=       remainder[i]+'A'-10;

}
  output[t]=0;
printf("%s\n",output);

return 0;

}


int main ()
{
	int number = 0;
	int inum[1000] ;
	int b, e;
	int p = 0;
	char cnum[1000];
	cin >> b >> cnum >> e;
	int len = strlen (cnum);
	int i;
	for (i = len - 1; i >= 0; i--)
	{
		if ( cnum [i] >= '0' && cnum[i] <= '9')
			inum[p++] = cnum[i] - '0';
		else if (cnum[i] >= 'a' && cnum[i] <= 'z')
			inum[p++] = cnum[i] - 'a' + 10;
		else inum[p++] = cnum[i] - 'A' + 10;
	}
	for (i = p - 1; i > 0; i--)
	{
		number = (number + inum[i]) * b;
	}
	int temp;
	number += inum[0];
	if (number == 0)
		cout << "0" << endl;
	for (i = 0; number > 0; i++)
	{
		temp = number % e;
		number = number / e;
		if (temp <= 9 && temp >= 0)
			cnum[i] = temp + '0';
		else
			cnum[i] = temp + 'a' - 42;
	}
	for (p = i - 1; p >= 0; p--)
		cout << cnum[p];
	cout << endl;
	return 0;
}


int main ()
{
	char string1[1000],string2[1000];
	int b,c=0,i,j=0,temp;
	float a,d;
	cin>>a>>string1>>d;
	b=strlen(string1);
	for(i=0;i<b;i++)
	{
		if(string1[i]>='0'&&string1[i]<='9')
			c+=(string1[i]-48)*pow(a,b-i-1);
		if(string1[i]>='a'&&string1[i]<='z')
			c+=(string1[i]-87)*pow(a,b-i-1);
		if(string1[i]>='A'&&string1[i]<='Z')
			c+=(string1[i]-55)*pow(a,b-i-1);
	}
	int index = 0;
	int e;
	if(c==0)
		cout<<'0'<<endl;
	while(c!=0)
	{
		e=c%(int)d;
		c=c/d;
		if(e>=10)
			string2[index]='A'+e-10;
		else
			string2[index] ='0'+e;
		index++;
	}
	for(i=index-1;i>=0;i--)
		cout<<string2[i];
	cout<<endl;
	return 0;
}


int main()
{
int a,b,c=0;
char num1[200],num2[200];
cin>>a>>num1>>b;
for(int i=0;i<strlen(num1);i++)
{
	if(num1[i]>='A'&&num1[i]<='Z')
		num1[i]+=32;
}
for(int i=0;i<strlen(num1);i++)
{
	if(num1[i]>='a'&&num1[i]<='z') c+=((int)num1[i]-87)*pow((double)a,(double)(strlen(num1)-1-i));
	else if(num1[i]>='1'&&num1[i]<='9') c+=((int)num1[i]-48)*pow((double)a,(double)(strlen(num1)-1-i));
}
if(c==0) cout<<c<<endl;
else{
	int j=0;
for(;;)
{
	if(c==0) break;
	if(c%b<10) num2[j]=(char)(c%b+48);
	else num2[j]=(char)(c%b+55);
	c=c/b;
	j++;
}
for(int i=j-1;i>=0;i--)
{
	cout<<num2[i];
}
cout<<endl;
}
return 0;
}


int main()
{
	int a,b,i,j,la,lb,decimal,number=0,t;
	char str1[1000],str2[1000]={'\0'};
	cin>>a;
	cin.get();
	cin.getline(str1,1000,' ');
	cin>>b;
	la=strlen(str1);
	for(i=0;i<la;i++)
	{

      if (str1[i] >= '0' && str1[i] <= '9')
             decimal = str1[i] - '0';
      else if(str1[i]>='A'&&str1[i]<='Z')
      		decimal = str1[i] - 'A' + 10;
	  else
		  decimal=str1[i]-'a'+10;
      number = number * a + decimal;
    }
	i=0;
	do
	{
		str2[i]=number%b;
		if(str2[i]>9)
			str2[i]=str2[i]-10+'A';
		else str2[i]=str2[i]+'0';
		number=number/b;
		i++;
	}
	while(number!=0);
	t=i;
	for(j=t-1;j>=0;j--)
	{
		cout<<str2[j];
	}

	return 0;
}


int main(){
	int a,b,i,zhen,chu,result;
	long x=0;
	char n[32],m[32];
	scanf("%d%s%d",&a,n,&b);
	result=strlen(n);

	for(i=0;i<result;i++){
		switch(n[i]){
		case '0':zhen=0;break;
		case '1':zhen=1;break;
		case '2':zhen=2;break;
                  case '3':zhen=3;break;
		case '4':zhen=4;break;
		case '5':zhen=5;break;
		case '6':zhen=6;break;
		case '7':zhen=7;break;
		case '8':zhen=8;break;
		case '9':zhen=9;break;
		case 'a':
        case 'A':
			zhen=10;
		    break;
		case 'b':
		case 'B':
			zhen=11;
			break;
		case 'c':
		case 'C':
			zhen=12;
			break;
		case 'd':
		case 'D':
			zhen=13;
			break;
		case 'e':
		case 'E':
			zhen=14;
			break;
		case 'f':
        case 'F':
			zhen=15;
			break;
		}
		x+=zhen*pow(a,result-1-i);
	}
	for(i=0;x>0;i++){
		chu=x%b;
		x=x/b;
		switch(chu){
        case 0:m[i]='0';break;
		case 1:m[i]='1';break;
        case 2:m[i]='2';break;
		case 3:m[i]='3';break;
        case 4:m[i]='4';break;
		case 5:m[i]='5';break;
		case 6:m[i]='6';break;
		case 7:m[i]='7';break;
		case 8:m[i]='8';break;
		case 9:m[i]='9';break;
		case 10:m[i]='A';break;
		case 11:m[i]='B';break;
		case 12:m[i]='C';break;
		case 13:m[i]='D';break;
		case 14:m[i]='E';break;
		case 15:m[i]='F';break;
		}
	}
	i=i-1;
	for(;i>=0;i--){
		printf("%c",m[i]);
	}
	printf("\n");
	return 0;
}


int convertorto10(char A[],int code,int right)
{
	if(right==0)
		return(A[0]-'0');
	else return(A[right]-'0'+code*convertorto10(A,code,right-1));
}
void main()
{
	int a,b,l,c,i,j;
	char n[100],nf[100],m[100],mf[100];
	scanf("%d %s%d",&a,n,&b);
	l=strlen(n);
	for(i=0;i<l;i++)
	{
		if(64<n[i]&&n[i]<91)
			nf[i]=n[i]-7;
		else if(n[i]>96)
			nf[i]=n[i]-39;
		else nf[i]=n[i];
	}
	c=convertorto10(nf,a,l-1);
	i=0;
	while(c/b>0)
	{
		m[i]=c%b;
		c=c/b;
		i=i+1;
	}
	m[i]=c;
	for(j=0;j<=i;j++)
		mf[j]=m[i-j];
	for(j=0;j<=i;j++)
	{
		if(mf[j]<10)
			mf[j]=mf[j]+48;
		else if(mf[j]>9)
			mf[j]=mf[j]+55;
	}
	for(j=0;j<=i;j++)
		printf("%c",mf[j]);
}


int main()
{
   int ah,af,i,j=0 ,len= 0,sum=0,jin=1 ,zhuan[100];
   char num[100],zhuanfu[100];
   cin>>ah;
   cin>>num;
   cin>>af;
   len = strlen(num);
   if( num[0]=='0' )
   printf("0");
   for( i = len-1;i >= 0;i--  )
   {
   if(num[i]>='a'&&num[i]<='z')
   num[i]-=87;
   if( num[i]>='A'&&num[i]<='Z' )
   num[i]-=55;
   if( num[i]>='0'&&num[i]<='9' )
   num[i]-=48;
   sum += num[i]*jin;
   jin*=ah;
   }
   while( sum != 0 )
   {
      zhuan[j]=sum%af;
      sum/=af;
      j++;
   }
   for( i = j-1;i>=0;i-- )
   {
   if( zhuan[i]>=10 )
   printf("%c",zhuan[i]+55);
   else
   printf("%d",zhuan[i]);
   }
}


int convertor(char A[],int code,int right)
{
	if(right==0)
		return(A[0]);
	else return(A[right]+code*convertor(A,code,right-1));
}

void main()
{int shuzhi1,shuzhi2,i,j,n,l;
 char num1[20],num2[20];
 scanf("%d",&shuzhi1);
 scanf("%s",num1);
 scanf("%d",&shuzhi2);
 n=strlen(num1);
 for(i=0;i<n;i++)
	{if(num1[i]>='A'&&num1[i]<='Z')
		 num1[i]=num1[i]-'A'+10;
     else if(num1[i]>='a'&&num1[i]<='z')
		 num1[i]=num1[i]-'a'+10;
	 else if(num1[i]>='0'&&num1[i]<='9')
		 num1[i]=num1[i]-'0';
	}
 l=convertor(num1,shuzhi1,n-1);
 j=0;
while(l/shuzhi2>0)
	{
	 num2[j]=l%shuzhi2;
     l=l/shuzhi2;
	 j++;
	}
 num2[j]=l;
 for(i=0;i<=j;i++)
	 	{if(num2[i]>9)
		 num2[i]=num2[i]-10+'A';
         else num2[i]=num2[i]+'0';
		}
 for(i=j;i>=0;i--)
	 printf("%c",num2[i]);
}


void main()
{
	int length,original,then,change[100],i,j,k,s=0,m,length2;
	char input[100],output[100];
	scanf("%d %s %d",&original,input,&then);
	length=strlen(input);
	for(i=0;i<length;i++)
	{
		if(input[i]<='9') change[i]=input[i]-48;
		else if(input[i]>='a') change[i]=input[i]-87;
		else change[i]=input[i]-55;
	}
	for(i=0;i<length;i++)
	{
		s=s+pow(original,length-i-1)*change[i];
	}
	for(j=0;;j++)
	{
		m=s%then;s=s/then;
		{
			if(s==0)
			{
				if((m<=9)&&(m>=0)) {output[j]=m+48;break;}
				else if((m>9)&&(m<=35)) {output[j]=m+55;break;}
			}
			else
			{
				if((m<=9)&&(m>=0)) output[j]=m+48;
		     	else if((m>9)&&(m<=35)) output[j]=m+55;
			}
		}
	}
	for(k=0;k<j+1;k++)
		printf("%c",output[j-k]);
	printf("\n");
}


int convert_1(char a){
   if (a >= '0' && a<= '9') return a - '0';
   if (a >= 'a' && a<= 'z') return a - 'a' + 10;
   if (a >= 'A' && a<= 'Z') return a - 'A' + 10;
}
char convert_2(int a){
    if (a < 10) return a + '0';
     else return a - 10 +'A';
}
void convert(int a,int n){
    if (a >= n) convert(a / n,n);
    printf("%c",convert_2(a % n));
}
int main(){
    int a,n = 0,b,k = 1,i;
    char str[500];
    scanf("%d %s %d",&a,str,&b);
    for(i = strlen(str) - 1;i >= 0;i --){
        n += convert_1(str[i]) * k;
        k *= a;
    }
    convert(n,b);
    printf("\n");
    return 0;
}


int main(){
	long int a,b,sum,c=0;
	char str[100],str1[100];
	cin>>a>>str>>b;
	for(int i=0;str[i]!='\0';i++)
		if((str[i]>='a')&&(str[i]<='z'))
			str[i]-=32;
	sum=strlen(str);
	for(int i=0;i<sum;i++){
		if(str[i]>='0'&&str[i]<='9')
			c+=(int)pow((double)a,(double)(sum-1-i))*(str[i]-48);
		if(str[i]>='A'&&str[i]<='Z')
			c+=(int)pow((double)a,(double)(sum-1-i))*(str[i]-55);
	}
	int Len=0;
	if(c==0)
		cout<<"0";
	else{
		while(c>0){
			int t=c%b;
			if (t>=10) str1[Len]='A'+t-10;
				else str1[Len]='0'+t;
			c/=b;Len++;
		}
		for(int j=Len-1;j>=0;j--)
			cout<<str1[j];
	}
	return 0;
}


int calc(char c)
{
if (c>='0' && c<='9') return c-'0';
else if (c>='a' && c<='z') return c-'a'+10;
else if (c>='A' && c<='Z') return c-'A'+10;
}
char form(int n)
{
if (n>=0 && n<=9) return '0'+n;
else return 'A'+n-10;
}
main()
{
int a,b,n,len,bs1;
char s[200];
char *p;
scanf("%d",&a);
scanf("%s",&s);
scanf("%d",&b);
len=strlen(s)-1;
bs1=1;
n=0;
int i;
for (i=len;i>=0;i--)
{
n+=bs1*(calc(s[i]));
bs1*=a;
}
if (n==0) printf("0");
for (i=0;n>0;i++)
{
s[i]=form(n%b);
n/=b;
}
for (int j=--i;j>=0;j--)
putchar(s[j]);
printf("\n");
}


int char_to_num(char c)
{
	if ('0'<=c && c<='9')
		return c-'0';
	if ('a'<=c && c<='z')
		return 10+(c-'a');
	if ('A'<=c && c<='Z')
		return 10+(c-'A');
}

char num_to_char(int n)
{
	if (n<10)
		return n+'0';
	else
		return n-10+'A';
}

int main()
{
	int a, b, i, length;
	char n[100];
	long num, pow;
	scanf("%d %s %d", &a, n, &b);
	length = strlen(n);
	pow = 1;
	num = 0;
	// get the number
	for (i=length-1; i>=0; i--)
	{
		num = num + char_to_num(n[i])*pow;
		pow = pow * a;
	}

	for (i=0; i<100; i++)
	{
		n[i] = num_to_char(num%b);
		num = num / b;
		if (num == 0)
			break;
	}
	for ( ; i>=0; i--)
		printf("%c", n[i]);
	printf("\n");

	return 0;
}


int main()
{
	int zheng[255];
	char fan[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int from,to;
	char in[255];
	scanf("%d%s%d",&from,in,&to);
	int i;
	for(i='0';i<='9';i++)
		zheng[i]=i-'0';
	for(i='A';i<='Z';i++)
		zheng[i]=i-'A'+10;
	for(i='a';i<='z';i++)
		zheng[i]=i-'a'+10;
	int sum=0;
	for(i=0;in[i];i++)
	{
		sum=sum*from+zheng[in[i]];
	}
	char out[255]="0";
	int l=0;
	l=(sum==0)?1:0;
	while(sum>0)
	{	out[l]=fan[sum%to];
		l++;
		sum/=to;
	}
	for(i=l-1;i>=0;i--)
		printf("%c",out[i]);
	return 0;

}


struct stack
{
    char data[101];
    int top;
};

long int change(int a, char *s);

int main()
{
    long int a, b, n;
    char str[101];

    while(scanf("%ld %s %ld", &a, str, &b) != EOF)
    {
        n = change(a, str);
        if(n == 0)
        {
            printf("0");
        }else
        {
            int temp;
            struct stack *s = (struct stack *)malloc(sizeof(struct stack));
            s->top = 0;

            while(n)
            {
                temp = n % b;
                if(temp >= 0 && temp <= 9)
                {
                    s->data[s->top ++] = temp + '0';
                }else
                {
                    s->data[s->top ++] = temp - 10 + 'A';
                }
                n /= b;
            }

            while(s->top)
            {
                printf("%c", s->data[-- s->top]);
            }
        }
        printf("\n");
    }

    return 0;
}

long int change(int a, char *s)
{
    int i, b;
    long int n, c;

    for(n = 0, c = 1, i = strlen(s) - 1; i >= 0; i --)
    {
        if(s[i] >= 'A' && s[i] <= 'Z')
            b = s[i] - 55;
        else if(s[i] >= 'a' && s[i] <= 'z')
            b = s[i] - 87;
        else
            b = s[i] - '0';
        n += b * c;
        c *= a;
    }

    return n;
}


void main()
{
	char shurudeshu[1000];int n,shijingzhi=0,i;
	int jingzhi,daizhuanhuandejingzhi;
	scanf("%d ",&jingzhi);scanf("%s ",shurudeshu);scanf("%d",&daizhuanhuandejingzhi);
	n=strlen(shurudeshu);
	for(i=0;i<=n-1;i++)
	{
		if(('A'<=shurudeshu[i])&&(shurudeshu[i]<='Z'))
			shurudeshu[i]=shurudeshu[i]-'A'+10;
		else if(('a'<=shurudeshu[i])&&(shurudeshu[i]<='z'))
			shurudeshu[i]=shurudeshu[i]-'a'+10;
		else if(('0'<=shurudeshu[i])&&(shurudeshu[i]<='9'))
			shurudeshu[i]=shurudeshu[i]-'0';
	}
		for(i=0;i<=n-1;i++)
		{
			shijingzhi=shijingzhi+(int)(shurudeshu[i]*pow(jingzhi,n-i-1));
		}
		if(shijingzhi==0)
			printf("%d",shijingzhi);
		if(shijingzhi!=0)
		{
		int shang;int yushu[100],j;
   shang=shijingzhi;
   for(i=0;shang!=0;i++)
   {
       yushu[i]=shang%daizhuanhuandejingzhi;
       shang=shang/daizhuanhuandejingzhi;
   }
   for(j=i-1;j>=0;j--)
   {
	   if((0<=yushu[j])&&(yushu[j]<=9))
		   printf("%d",yushu[j]);
	   else if(yushu[j]>=10)
	   {
		   yushu[j]=yushu[j]+'A'-10;
	       printf("%c",yushu[j]);
	   }
   }
		}
   printf("\n");
}


int main(int argc, char* argv[])
{
	int a2i[128];
	char i2a[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char in[255],out[255]="0";
	int i,from,to,len=0;
	long num=0;
	for(i='0';i<='9';i++)
	   a2i[i]=i-'0';
	for(i='A';i<='Z';i++)
		a2i[i]=i-'A'+10;
	for(i='a';i<='z';i++)
		a2i[i]=i-'a'+10;
	scanf("%d%s%d",&from,in,&to);
	for(i=0;in[i]!='\0';i++)
		num=num*from+a2i[in[i]];
	len=(num==0)?1:0;
	while(num>0)
	{
		out[len++]=i2a[num%to];
		num/=to;
	}
	for(i=len-1;i>=0;i--)
		printf("%c",out[i]);
	return 0;
}


int main()
{
	int a,b,i=0,j=0,k=0,shijinzhi=0,power=1;
	int x[30];
	cin>>a;
    x[0]=getchar()+1;
	while(x[i]!=-16)
	{
		i++;
		x[i]=getchar();
		if(x[i]>96) x[i]-=87;
		else if(x[i]>64) x[i]-=55;
		else x[i]-=48;
	}
	if (x[1]==0) cout<<"0";
	else
	{
	for(j=i-1;j>=1;j--)
	{
		shijinzhi+=x[j]*power;
		power=power*a;
	}
	cin>>b;
	i=0;
	while(shijinzhi>0)
	{
		i++;
		x[i]=shijinzhi%b;
		shijinzhi=shijinzhi/b;
		if(x[i]<10) x[i]+=48;
		else x[i]+=55;
	}
	for(k=i;k>0;k--)
	{
		putchar(x[k]);
	}
	}
	return 0;
}


int chrtoint(char ch)
{
	if (ch>='0' && ch<='9')
		return ch-'0';
	else if (ch>='A' && ch<='Z')
		return ch-'A'+10;
	else if (ch>='a' && ch<='z')
		return ch-'a'+10;
	else
		return -1;
}

char inttochr(int a)
{
	if (a>=0 && a<=9)
		return (char)(a+'0');
	else if (a>=10 && a<=35)
		return (char)(a-10+'A');
	else
		return -1;
}

int main()
{
	char str[100]={0};
	long a, b;
	long num;
	scanf("%d %s %d", &a, str, &b);
	int len=0, i;
	while (str[len]>0)
		len++; //???????

	//a??->10??
	num=0;
	for (i=0;i<len;i++)
	{
		num=num*a+chrtoint(str[i]);
	}

	//10??->b??
	str[0]='0';
	len=0;
	while (num>0)
	{
		str[len]=inttochr(num%b);
		len++;
		num/=b;
	}
	if (len==0) len++; //??0???

	//????
	for (i=len-1;i>=0;i--)
		putchar(str[i]);

	return 0;
}


void main()
{
unsigned long intonumber(char x);
char intochar(int y);
char str[N];
char former[3];
gets(str);
int i=0,c1=0,c2=0;
while(str[i]!=' ')
{
	former[i]=intonumber(str[i]);
	c2=c1+former[i];
	c1=c2*10;
	i++;
}
i++;
int j=0;
unsigned long n2=0,n1=0;char num[N];
while(str[i]!=' ')
{
	num[j]=intonumber(str[i]);
	n2=n1+num[j];
	n1=n2*c2;
	j++;i++;

}
i++;int k=0,l1=0,l2=0;char later[3];
while(str[i]!='\0')
{
later[k]=intonumber(str[i]);
l2=l1+later[k];
l1=l2*10;
i++;k++;

}

int f;char yu[M];
for(f=0;n2>0;f++)
{
	yu[f]=intochar(n2%l2);
	n2=n2/l2;
}

if(f==0)printf("%d",0);
for(f--;f>=0;f--)
printf("%c",yu[f]);
}

unsigned long intonumber(char x)
{
	if(x>='a'&&x<='z')
		x=x-87;
	else if(x>='A'&&x<='Z')
		x=x-55;
	else if(x>=48&&x<=57)
		x=x-48;
	return(x);
}

char intochar(int y)
{
	if(y>=0&&y<=9)
		y=y+48;
	else if(y>9&&y<=32)
		y=y+55;
	return(y);

}


int main()
{int a,b,num;
int i=1,j=1,k=1,count=0;
long sum=0;
long sum1;
char n[100];
for(k=0;k<100;k++)
{n[k]='\0';
                  }
cin>>a>>n>>b;
for(count=0;count<100;count++)
{if(n[count]=='\0')
{num=count;
break;
}
}
     int shu[num];
for(i=0;i<num;i++)
{shu[i]=n[i];
if(shu[i]<58)
shu[i]=shu[i]-48;
else if(shu[i]<91)
shu[i]=shu[i]-55;
else
shu[i]=shu[i]-87;
                     }
for(i=0;i<num;i++)
{
                  sum=sum+shu[i]*(long)pow((double)a,(double)(num-i-1));
                   }
                   sum1=sum;
for(i=1;i<100;i++)
{sum1=sum1/b;
if(sum1==0)
{break;}
                  }
long shu1[i];
for(j=0;j<i;j++)
{shu1[j]=sum%b;
sum=sum/b;
}
char m[i];
for(j=0;j<i;j++)
{if(shu1[i-j-1]<10)
m[j]=shu1[i-j-1]+48;
else
m[j]=shu1[i-j-1]+55;
cout<<m[j];
}
return 0;
    }


main()
{
int x,y;int rest;int r,s,t;
char NUM[150];
scanf("%d %s %d",&x,NUM,&y);
int LEN;
LEN=strlen(NUM);
int i,j,k;int m=0,n=0;
char a='a',A='A',Z='Z',z='z';
char zero='0',nine='9';
for (i=0;i<LEN;i++)
{
if (NUM[i]>=a&&NUM[i]<=z)
NUM[i]=NUM[i]-a+10;
if (NUM[i]>=A&&NUM[i]<=Z)
NUM[i]=NUM[i]-A+10;
if (NUM[i]>=zero&&NUM[i]<=nine)
NUM[i]=NUM[i]-zero;
}
for (i=0;i<LEN;i++)
{
m=NUM[i];
for (j=1;j<=LEN-i-1;j++)
m*=x;
n+=m;
}
rest=n;
for (i=0;;i++)
{
if (rest==0) break;
rest/=y;
}
int PUT[1000];
int kk=i;
for (;kk>=1;kk--)
{
r=n%y;
n/=y;
PUT[kk-1]=r;
}
if (i==0) printf("0");
else for (j=0;j<i;j++)
{
if (PUT[j]>=10)
printf("%c",PUT[j]-10+A);
else
printf("%d",PUT[j]);
}
printf("\n");
}


int main()
{
	int wan,ge,shi,bai,qian;
	long int zheng;
	scanf("%d",&zheng);
	wan=zheng/10000;
	qian=zheng/1000-wan*10;
	bai=zheng/100-wan*100-qian*10;
	shi=zheng/10-wan*1000-qian*100-bai*10;
	ge=zheng-wan*10000-qian*1000-bai*100-shi*10;
	if(wan)
		printf("%d",wan+qian*10+bai*100+shi*1000+ge*10000);
		else
		if(qian)
				printf("%d",qian+bai*10+shi*100+ge*1000);
		else
			if(bai)
				printf("%d",bai+shi*10+ge*100);
			else
				if(shi)
					printf("%d",shi+ge*10);
				else
					printf("%d",ge);

}


int main()
{
	short length,i,j=1;
	char number[6];
		while(j<=4)
		{
			scanf("%s",number);
			length=strlen(number);
			for(i=length-1;i!=-1;i--)
			{
				printf("%c",number[i]);
			}
			putchar('\n');
			j++;
		}
	return(0);
}


int main()
{

char a, b, c, d, e;
a=getchar();
b=getchar();
c=getchar();
d=getchar();
e=getchar();
if( e >= '0' && e <= '9') putchar(e);
if( d >= '0' && d <= '9') putchar(d);
if( c >= '0' && c <= '9') putchar(c);
if( b >= '0' && b <= '9') putchar(b);
if( a >= '0' && a <= '9') putchar(a);
}


int main(int argc, char* argv[])
{
	int k=0,i,t;
	char num[6],rum[6];
	scanf("%s",num);
	for (i=0;num[i]!='\0';i++)
	{
      k=k+1;
	}
    for (i=0;num[i]!='\0';i++)
	{
		t=k-i-1;
		rum[t]=num[i];
	}
	rum[k]='\0';

		printf("%s\n",rum);

	return 0;
}


int main()
{
	char num[10];
	int n;
	while(cin>>n){
		int i = 0;
		while(n!=0){
			num[i++]= n%10+'0';
			n /= 10;
		}
		num[i]= '\0';
		cout<<num<<endl;
	}
	return 0;
}


int main(){
    char ch[6];
    char c;
    int j,k,n=0;
    do
    {
         n++;
         ch[n-1]=getchar();
    }while(ch[n-1]!='\n');
    n--;
    for(j=0;j<n/2;j++)
    {
        c=ch[j];
        ch[j]=ch[n-1-j];
        ch[n-1-j]=c;
    }
    for(k=0;k<n;k++)
       putchar(ch[k]);
    return 0;
}


void main ()
{
char a, b, c, d, e;
a=getchar();
b=getchar();
c=getchar();
d=getchar();
e=getchar();
if(e>='0'&&e<='9')
{putchar(e);putchar(d);putchar(c);putchar(b);putchar(a);}
else if(!(e>='0'&&e<='9'))
{
	if(d>='0'&&d<='9')
    {putchar(d);putchar(c);putchar(b);putchar(a);}
	else if(!(d>='0'&&d<='9'))
	{
		if(c>='0'&&c<='9')
		{putchar(c);putchar(b);putchar(a);}
		else if(!(c>='0'&&c<='9'))
		{
			if(b>='0'&&b<='9')
			{putchar(b);putchar(a);}
			else if(!(b>='0'&&b<='9'))
				putchar(a);
		}
	}
}
}


char a[6];
int i,j;
void replace(int i,int j)
{
	int temp;
	if(i<j)
	{
		temp=a[i];
		a[i]=a[j];
		a[j]=temp;
		replace(i+1,j-1);
	}
	else return;
}
void main()
{
	gets(a);
	replace(0,strlen(a)-1);
	puts(a);
}


void main()
{
	char *str;
	str=(char*)malloc(5*sizeof(char));
	char*p;
	p=str;
	gets(str);
	for(p=str+strlen(str)-1;p>=str;p--)
		printf("%c",*p);

}


void main()
{
 char a,b,c,d,e,x,y;
 scanf("%c%c%c%c%c",&a,&b,&c,&d,&e);
 if(c=='\n')
  {x=a;
   a=b;
   b=x;
   printf("%c%c",a,b);}
 else if(d=='\n')
   {x=a;
    a=c;
    c=x;
    printf("%c%c%c",a,b,c); }
else if(e=='\n')
   {x=a;
    a=d;
    d=a;
    y=b;
    b=c;
    c=y;
    printf("%c%c%c%c",a,b,c,d);}
else {x=a;
      a=e;
      e=x;
      y=b;
      b=d;
      d=y;
     printf("%c%c%c%c%c",a,b,c,d,e);}
}


void main ()
{

	char num[5];
	int i,flag=0,j;
	for (i=0;flag==0;i++)
	{
		scanf("%c",&num[i]);
		if (num[i]>'0'&& num[i]<='9')
			flag=0;
		else
			flag=1;
	}
	for (j=i-2;j>=0;j--)
		printf("%c",num[j]);

}


void main()
{
 int i=0;
 char str[10];
 scanf("%s",str);
 while(str[i]!='\0')
  i++;
 for(i--;i>=0;i--)
 printf("%c",str[i]);
 printf("\n");
}


void main()
{
	char c;
	int y;
	y=0;
	int t;
	t=1;
	c=getchar();
	while (c!=10)
	{
		y=y+(c-48)*t;
		t=t*10;
		c=getchar();
	}
	printf("%d",y);
}


int main()
{
    void a(int x,int y);
    int n;
    scanf("%d",&n);
    a(n,10000);
        return 0;
}

void a(int x,int y)
{
     int t,k,p;

     t=x/y;
     x=x-t*y;
     if(y==1)printf("%d",t);
     else
     {
         a(x,y/10);
         if(t==0);
         else printf("%d",t);
     }

}


 int m=0,k=0,j=0;
void main()
{
	int n;
	int v(int a);
	scanf("%d",&n);
	printf("%d",v(n));
}
  int v(int a)
  {

  	if(a!=0)
  	{
  	m=a%10;
  	k=a/10;
  	j=j*10+m;

  	v(k);
  	}

  	return(j);
  }


int main()
{
	int *x, y;
	int i;
	x=malloc(4*sizeof(int));
	for(i=0; i<4; i++)
	{
		scanf("%d", x+i);
	}
	for(i=0; i<4; i++)
	{
		y=*(x+i);
		while(y!=0)
	{
		printf("%d", y % 10);
		y = y / 10;
	}
		printf("\n");
	}

	return 0;
}


void main()
{
	int a,d,c,b=10;
	scanf("%d",&a);
	while(c!=0)
	{
	d=b/10;
	c=(a%b-a%d)/d;
	b=b*10;
	if(c!=0)
	printf("%d",c);
	else
	break;
	}
}


int main()
{
	int number,a,b,c,d,e;
	scanf("%d",&number);
	a=0;
	b=0;
	c=0;
	d=0;
	e=0;
	if(number<10&&number>=0)
		printf("%d",e);
	if(number<100000&&number>=10000)
	{
		a=number/10000;
		number=number-a*10000;
	}
	if(number<10000&&number>=1000)
	{
		b=number/1000;
		number=number-b*1000;
	}
	if(number<1000&&number>=100)
	{
		c=number/100;
		number=number-c*100;
	}
	if(number<100&&number>=10)
	{
		d=number/10;
		number=number-d*10;
	}
	e=number;
	if(a!=0)
		printf("%d%d%d%d%d",e,d,c,b,a);
	else
	{
		if(b!=0)
			printf("%d%d%d%d",e,d,c,b);
		else
		{
			if(c!=0)
				printf("%d%d%d",e,d,c);
			else
			{
				if(d!=0)
					printf("%d%d",e,d);
			}
		}
	}
}


int main(int argc, char* argv[])
{
	char a[5], t[5];
	int n, i;
	scanf("%s", a);
	n=strlen(a);
    for(i=0;i<n;i++){
	   t[n-i-1]=a[i];
	}
	t[n]='\0';
	printf("%s\n", t);
	return 0;
}


int main( int argc, char* argv[] ){
	char str[5];
	int i, count;

	scanf( "%s", str );

	count = strlen(str);
	for ( i = count - 1; i >= 0; i-- ){
		printf( "%c", str[i] );
	}

	return 0;

}


int main(){
    char zfc[5];
    int i,a;
    scanf("%s",zfc);
    for(i=0;i<strlen(zfc)/2;i++){
        a=zfc[i];
        zfc[i]=zfc[strlen(zfc)-i-1];
        zfc[strlen(zfc)-i-1]=a;
    }
    printf("%s",zfc);
    return 0;
}


int main()
{
	char num[5];
	gets(num);
	for(int i=strlen(num)-1;i>=0;i--)
	{
		printf("%c",num[i]);
	}
	getchar();
	getchar();
	return 0;
}


int main(int argc,char *argv[])
{
    char a[6];
    scanf("%s",&a);
    int n,i;
    for(i=0;i<=5;i++)
    {
     if(a[i]=='\0')
     {
      n=i;
      break;
      }
     }
    for(i=n-1;i>=0;i--)printf("%c",a[i]);
    printf("\n");
    return 0;
}


int main ()
{
	int n;
	scanf ("%d",&n);
	int i,r = 0,t = n,a,tmp;
	do
	{
		t=(int)(t/10);
		r++;
	}while (t>0);
	for (i=0;i<r;i++)
	{
		t = n/(int)pow(10,i);
		a = t%10;
		printf ("%d",a);
	}
	return 0;
}


void main()
{
 int n;
scanf("%d",&n);
r(n);
}

r(int m)
{
printf("%d",m%10);
m=m/10;
if(m!=0)
return r(m);
}


int main()
{
	void print(int n);
	int n;
	scanf("%d",&n);
	print(n);
	return 0;
}

void print(int n)
{
	if(n<10)
		printf("%d",n);
	else
	{
		printf("%d",n%10);
		print(n/10);
	}
}


void main()
{
	void NIXU(int x);
	int n;
	scanf("%d",&n);
	NIXU(n);
}
void NIXU(int x)
{
	int i;
	if((i=x/10)!=0)
	{
		putchar(x%10+'0');
		NIXU(i);
	}
	else putchar(x+'0');
}


int main()
{
	int i,k;
	char list[5],list1[5];

	gets(list);
	for(k=0;k<5;k++)
		if(list[k]=='\0')
			break;

	for(i=0;i<k;i++)
		list1[i]=list[k-i-1];
	for(i=0;i<k;i++)
	{
		printf("%c",list1[i]);
	}

	return 0;
}


int main(int argc, char* argv[])
{
	int i ,j;
   char num[5];
   for(i=0;i<5;i++)

   scanf("%c",&num[i]);
   for(j=4;j>=0;j--)
  	if (num[j]!=0)
	printf("%c",num[j]);
   return 0;

}


void main()
{
   int x,u,i,result;
   long t;
   scanf("%d",&x);
   u=floor(log10(x));
   result=0;
   for (i=1;i<=u+1;i++)
   {
	   t=pow(10,i);
	  result=result+floor(((x%t)/pow(10,i-1)))*pow(10,u-i+1);
   }
   printf("%ld",result);
}


nixu(int n)
{
int m;
m=n%10;
	printf("%d",m);
	m=n/10;
if (m<1) ;
else m=nixu(m);
	return m;
}

void main()
{
int n;

scanf("%d",&n);

nixu(n);

}


int main()
{
  int num;
  scanf("%d",&num);
 if(num>9999&&num<100000)
 {int ten_thousand,thousand,hundred,ten,a;
	 ten_thousand=(int)(num/10000);
  thousand=(int)(num-ten_thousand*10000)/1000;
  hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
  ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
 a=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
printf("%d%d%d%d%d\n",a,ten,hundred,thousand,ten_thousand);
 }
else
 if (num>999&&num<10000)
 {int ten_thousand,thousand,hundred,ten,a;
	 ten_thousand=(int)(num/10000);
  thousand=(int)(num-ten_thousand*10000)/1000;
  hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
  ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
 a=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
printf("%d%d%d%d\n",a,ten,hundred,thousand);
 }
else
 if (num>99&&num<1000)
 {int ten_thousand,thousand,hundred,ten,a;
	ten_thousand=(int)(num/10000);
  thousand=(int)(num-ten_thousand*10000)/1000;
  hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
  ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
 a=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
printf("%d%d%d\n",a,ten,hundred);
 }
else
 if (num>9&&num<100)
 {int ten_thousand,thousand,hundred,ten,a;
	 ten_thousand=(int)(num/10000);
  thousand=(int)(num-ten_thousand*10000)/1000;
  hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
  ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
 a=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
printf("%d%d\n",a,ten);
 }
else
 if (num>0&&num<10)
 {int ten_thousand,thousand,hundred,ten,a;
	 	 ten_thousand=(int)(num/10000);
  thousand=(int)(num-ten_thousand*10000)/1000;
  hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;
  ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
 a=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);
printf("%d\n",a);
 }
return 0;
}


int main(int argc, char* argv[])
{

       int number;

       int reversed_number = 0;

       int remainder = 0;

       scanf("%d",&number);

       while(number != 0){

              remainder = number % 10;

              reversed_number *= 10;

              reversed_number += remainder;

              number /= 10;

       }

       printf("%d\n",reversed_number);

	return 0;
}


void print(int n)
{
      int p=n;int i;
      if(p/10!=0)
      {
         for(i=0;p/10!=0;i++)
         {
                         int temp=p/10;
                         p=p-10*temp;
         }
         printf("%d",p);
         n=n/10;
         print(n);
      }
      else
      printf("%d",n);
}

main()
{
      int number,i;
      scanf("%d",&number);
      print(number);
    }


int main()
{
  char a,b,c,d,e;
  a=b=c=d=e=0;
  scanf("%c%c%c%c%c",&a,&b,&c,&d,&e);
  if(e!='\n'&&e)
    putchar(e);
  if(d!='\n'&&d)
    putchar(d);
  if(c!='\n'&&c)
    putchar(c);
  if(b!='\n'&&b)
    putchar(b);
  putchar(a);
}


void main()
{
  int num,i,num2=0,b;
  scanf("%d",&num);
  for(i=1;i<=6;i++)
   {
    b=num%10;
    num=num/10;
    if(b!=0) num2=num2*10+b;
      }
printf("%d",num2);
}


void main()
{
	int m,n;
	scanf("%d",&n);
	char str[10];
	sprintf(str,"%d",n);
	m=strlen(str);
	char *p;
	p=str;
	for(p=str+m-1;p>=str;p--)
		printf("%c",*p);
}


int main()
{
int n,i,a;
scanf("%d",&n);
while(n>0)
{
a=n%10;
n=n/10;
i++;
printf("%d",a);
}
return 0;
}


void change(char s[],int i);

void main()
{
	char s[6];
	int i;
	gets(s);
	for(i=0;i<6;i++)
	if(s[i]=='\0')break;
	change(s,i);
}

void change(char s[],int i)
{
	if(i==1)putchar(s[0]);
	else
	{
		printf("%c",s[i-1]);
		change(s,i-1);
	}
}


int main()
{
	int a,b;
	cin >>a;
	b=0;
	while (a!=0)
	{
		b=b*10+a%10;
		a=a/10;
	}
	cout <<b<<endl;
	return 0;
}


int main()
{

	char a,b,c,d,e;
int i=0;
scanf("%c%c%c%c%c",&a,&b,&c,&d,&e);
if(i!='\n')
printf("%c%c%c%c%c\n",e,d,c,b,a);
return 0;
}


int main(int argc, char* argv[])
{
	char str[10],a;
	int i=0,n;
	gets(str);
	char *p=str;
	do{
         i++;
		 p++;
		 a=*p;
	}while(a!='\0');
	n=i;
	char s[10];
	for(i=0;i<n;i++)s[i]=str[n-i-1];
	for(i=0;i<n;i++)printf("%c",s[i]);
    return 0;
}


int main(int argc, char* argv[])
{
	int a,b;
	int shu[5];
	int i;
	scanf("%d",&a);
	b=a;

    int wei=0;
	do{
		a=a/10;
		wei++;
	}while(a!=0);

	for(i=0;i<wei;i++){
		shu[i]=b/pow(10,wei-1-i);
		b=b-shu[i]*pow(10,wei-1-i);
	}
    int sum=0;
	for(i=0;i<wei;i++){
		sum=sum+shu[i]*pow(10,i);
	}
	printf("\n%d",sum);

	return 0;
}


void main()
{
	char a[5],b[5];
	int i,num;
	for (num=0,i=0;(a[i]=getchar())!='\n';i++)
		num++;
    for (i=0;i<num;i++)
		b[i]=a[num-i-1];
	for (i=0;i<num;i++)
		printf("%c",b[i]);
}


int main()
{
	int n,i,j;
	char c[5];
	scanf("%s",&c);
	n=strlen(c);
	for(i=0;i<n;i++)
	{
		j=n-i-1;
		printf("%c",c[j]);
	}
	return 0;
}


int main()
{
    int num[5]={'\0'};
    long number;
    int i,place=1;

    scanf("%ld",&number);
    do {
    place=1;
    for(i=0;i<=4;i++) {
        num[i]=number%10;
        number/=10;
        if(number!=0)
            place+=1;
    }
    for(i=0;i<place;i++)
        printf("%d",num[i]);
    printf("\n");
    scanf("%ld",&number);
    }while(number!=0);
    return 0;
}


void change(char *);
int main()
{
	char *p;
	p = (char*)malloc(5*sizeof(char));
	gets(p);

	change(p);
}
void change(char *q){
	char *q0 = q;
	if (*q=='\0') printf("\n");
	else {
        for (;*q!='\0';q++){}
		printf("%c",*(q-1));
		*(q-1)='\0';
		change(q0);
	}
}


int n=0;
void main()
{
	int a,f=0;
	int v(int z);
	int s(int x);
	int h(int y);
	scanf("%d",&a);
	f=v(a);
	printf("%d",f);
}
int s(int x)
{
	int b;
	if (x>9999) b=x/10000;
	else if(x>999) b=x/1000;
	else if(x>99)  b=x/100;
	else if(x>9)  b=x/10;
	else b=x;
	return(b);
}
int h(int y)
{
int b;
	if (y>9999) b=fmod(y,10000);
	else if(y>999) b=fmod(y,1000);
	else if(y>99)  b=fmod(y,100);
	else if(y>9)  b=fmod(y,10);
	else b=0;
	return(b);
}
int v(int z)
{
	int n;
    if (z<10) n=z;
	else n=v(h(z))*10+s(z);
	return(n);
}


int main(int argc, char* argv[])
{
	int a,b=0;
	scanf("%d",&a);
    while(a>9)
	{
		b=(a-a/10*10)*10+b*10;
		a=a/10;
	}
	b=b+a;
	printf("%d",b);
	return 0;
}


long fang(long x);
 void main()

 {

 long sum,a,b,i,t,s,p;

 sum=0;

 scanf("%d",&a);

 i=4;

 p=10000;

 s=a/p; // s=a/p; b=a%p;

 while(s==0)

 {

 i=i-1;

 p=fang(i);

 s=a/p; // s=b/p; b=b%p;

 }

 t=i;

 while(t>=0)

 {

 b=a%10;

 a=a/10;

 sum=sum+fang(t)*b;

 t=t-1;

 }

 printf("%d",sum);

 }

 long fang(long x)

 {

 long i,y;

 i=1;

 y=1;

 while(i++<=x)     //  while(i++<=x)

 y=y*10;

 return(y);

 }


void main()
{
	char a[10];
	int i,j;
	for (i=0;;i++)
	{
		a[i]=getchar();
		if (a[i]=='\n') break;
	}
	j=i-1;
	for (i=j;i>=0;i--)
		printf("%c",a[i]);
}


int main()
{
    char a[6];
    int c;
    int i=0;
    do
    {
         c=getchar();
         a[i]=c;
          i++;
    }
    while (c!='\n');
    i-=2;
    for (;i>=0;i--)
    {
        cout<<a[i];
    }
}


void echo()
{
	char c1;
	scanf("%c",&c1);
	if(c1!='\n')
	echo();
	printf("%c",c1);
}
   int main()
   {echo();}


int main()
{
	char str[80],*p,*q,t;
	scanf("%s", str);
	for(p=str,q=p+strlen(str)-1;p<q;p++,q--)
	{
		t=*p;
		*p=*q;
		*q=t;
	}
	printf("%s", str);
	return 0;
}


int main(int argc, char* argv[])
{
    int x,y=0;
	scanf("%d",&x);
	while(x>0){
		y=(y+x%10)*10;
		x=x/10;
	}
	y=y/10;
	printf("%d\n",y);
	return 0;
}


int main(){
int a;
char zfc[6],exc[6];
scanf("%s",zfc);
a=strlen(zfc);
for(int i=0;i<a/2;i++){
exc[i]=zfc[i];
zfc[i]=zfc[a-i-1];
zfc[a-i-1]=exc[i];}
printf("%s\n",zfc);
return 0;
}


main()
{
	char a[5];
	scanf("%s",a);
	int l=strlen(a);
	char *p;

	p=(char*)malloc(l*sizeof(char));
		p=a;
	int i;
	for(i=1;i<=l/2;i++)
	{
		char b;
		b=*(p+i-1);
		*(p+i-1)=*(p+l-i);
		*(p+l-i)=b;
	}
	for(i=0;i<l;i++)
		printf("%c",*(p+i));
}


void main()
{
int b,c,n,i;
char a[5];
gets(a);
b=strlen(a);

for(i=b-1;i>=0;i--)
{
	printf("%c",a[i]);
}
getchar();

}


void main()
{
 int n;
 int r( int m );
scanf("%d",&n);
r(n);
}

r( int m )
{ printf("%d",m%10);
m =m/10;
if( m!=0)
return r(m);
}


int main()
{
	char ch,a,b,c,d,e;
	int n;
	n=0;
    while (scanf("%c",&ch)!=EOF)
	{
		n=n+1;

		switch(n)
		{
		case 1:a=ch;break;
		case 2:b=ch;break;
        case 3:c=ch;break;
		case 4:d=ch;break;
		case 5:e=ch;break;
		}
	}

	while (n>0)
	{

		switch(n)
		{
		case 5:printf("%c",e);break;
		case 4:printf("%c",d);break;
		case 3:printf("%c",c);break;
		case 2:printf("%c",b);break;
		case 1:printf("%c",a);break;
		}
			n=n-1;
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int n,y=0;
	scanf("%d",&n);
	while(n>9)
	{
		y=y+n-n/10*10;
		n=n/10;
		y*=10;
	}
	y=y+n;
	printf("%d\n",y);
	return 0;
}


void main()
{
    int n;
	scanf("%d",&n);
    void move(int n);
	move(n);
}
void move(int n)
{
	while(n!=0)
	{
	printf("%d",n%10);
	n=n/10;
	}
}


int main()
{
	char a[5],b[5];
	int i,j;
	gets(a);
	int length=(int)strlen(a);
	for(i=length-1,j=0;i>=0;i--,j++)
		b[j]=a[i];
	b[j]='\0';
	puts(b);
	return 0;
}


void main()
{
	int n,a,b,c,d,e,place;
	scanf("%d",&n);
	if (n>9999)
		place=5;
	else
     if (n>999)
		place=4;
 else if (n>99)
		place=3;
else  if (n>9 )
		place=2;
else place=1;
a=n/10000;
b=(n-10000*a)/1000;
c=(n-10000*a-1000*b)/100;
d=(n-10000*a-1000*b-100*c)/10;
e=n%10;
switch (place)
{
case 1: printf("%d",e); break;
case 2: printf("%d%d",e,d); break;
case 3: printf("%d%d%d",e,d,c); break;
case 4: printf("%d%d%d%d",e,d,c,b); break;
case 5: printf("%d%d%d%d%d",e,d,c,b,a); break;
}
}


void main()
{
	char a,b,c,d,e;
a=getchar();
b=getchar();
c=getchar();
d=getchar();
e=getchar();
if (e<='9' && e>='0' && e!=	EOF)
putchar(e);
if (d<='9' && d>='0' && d!=	EOF)
putchar(d);
if (c<='9' && c>='0' && c!=	EOF)
putchar(c);
if (b<='9' && b>='0' && b!=	EOF)
putchar(b);
if (a<='9' && a>='0' && a!=	EOF)
putchar(a);
}


int num,i,c;
int a[5];
void main()
{
 void move(int j,int k);
        scanf("%d",&num);
  if(num>=10000) {c=4;move(num,c);}
  else if(num>=1000&&num<10000) {c=3;move(num,c);}
  else if(num>=100&&num<1000) {c=2;move(num,c);}
  else if(num>=10&&num<100) {c=1;move(num,c);}
  else {c=0;move(num,c);}
 for(i=0;i<=c;i++)
  printf("%d",a[i]);
}
void move(int j,int k)
{
 if(k>0)
 {
 a[k]=(int)(j/(int)pow(10,k));
 int o=(int)(j%(int)pow(10,k));
    move(o,k-1);
 }
 else if(k==0)
 {a[k]=j;
 }
}


void Reverse(int n)
{
     if(n>0)
	 {
        printf("%d",n%10);
        Reverse(n/10);
	 }
}
int main()
{
     int num;
    scanf("%d",&num);
     Reverse(num);
     printf("\n");
     return 0;
}


int l;
int main()
{
	char a[5];
	int n;
	void pailie(int n,char ar[]);
   	gets(a);
	l=strlen(a);
	n=l;
	pailie(n,a);
	return 0;
}
void pailie(int n,char ar[])
{
	if(n==1)printf("%c",ar[l-n]);
	else
	{
		pailie(n-1,ar);
		printf("%c",ar[l-n]);
	}
}


int main()
{
	int x,y;
	scanf("%d",&x);
	do{
		y=x%10;
		printf("%d",y);
		x/=10;
	}while(x);
	return 0;
}


int main()
{
	void f(int x);
	int x;
	scanf("%d",&x);
	f(x);
	return 0;
}
void f(int x)
{
	if (x>=10)
	{
		printf("%d",x%10);
		int y;
		y=(x-x%10)/10;
		f(y);
	}
	else printf("%d\n",x);
}


int main(int argc, char* argv[])
{
	char num[5],chu[5];
	scanf("%s",&num);
	int a=0,i,j,e=0;
	for(i=0;num[i]!='0'&&num[i]!='\0';i++)
	{
		a++;
	}

	for(j=a-1;j>=0;j--)
	{
		chu[e]=num[j];
		e++;
	}
	printf("%s",chu);

	return 0;
}


int main(int argc, char* argv[])
{
	int i, len;
	char s[6], t;

	gets(s);
	len = strlen(s);

	for (i = 0; i < (len/2); i++)
	{
		t = s[len - (i+1)];
		s[len-(i+1)] = s[i];
		s[i] = t;
	}
	printf("%s", s);
	return 0;
}


int main()
{
    char num[10],temp;
    int i,j;
    scanf("%s", num);
    for(i=0;i<floor(strlen(num)/2);i++)
    {
                                                                  temp=num[i];
                                                                  num[i]=num[strlen(num)-i-1];
                                                                  num[strlen(num)-i-1]=temp;
    }
    for(i=0;i<strlen(num);i++)
    {
                              printf("%c",num[i]);
    }
    return 0;
}


void main()
{
     char a,b,c,d,e;
     scanf("%c%c%c%c%c",&a,&b,&c,&d,&e);
     printf("%c%c%c%c%c\n",e,d,c,b,a);
}


void main()
{
   int di,number,k,j,n;
   n=1;
   di=10;
   scanf("%d",&number);
   do
   {
	   j=number-di;
   if(j>0)
   {
   n=n+1;
   di=di*10;
   }
   }
   while(j>0);
   j=0;
   di=10;
   do
   {
	   k=((number%di)-(number%(di/10)))/(di/10);
	   printf("%d",k);
       di=di*10;
	   j=j+1;
   }
while(j<n);
}


int main ()
{
	char ch[5], a;
	int i, n=0;
	for (i=0; (ch[i]=getchar())!='\n'; i++)
			n++;
	for (i=n-1; i>=0; i--)
	printf ("%c", ch[i]);
	return 0;
}


int main()
{
	int m,i;
	char a[6];
	scanf("%s",a);
    m=strlen(a);
	for(i=m;i>=0;i--)
	{
		if(a[i]=='\0') continue;
		else printf("%c",a[i]);
	}
	return 0;
}


int main(){
	char zfc[100], exc;
	int len, i;
	scanf("%s", zfc);
        len = strlen(zfc);
for(i = 0; i < len/2; i++){
	exc = zfc[i];
	zfc[i] = zfc[len-1-i];
	zfc[len-1-i] = exc;
}

printf("%s", zfc);

	return 0;
}


int main ()
{
	long n;
	int a[5];
	scanf("%ld", &n);

	int m = (int)log10(n);
	int i;
	for (i = 0; i <= m; i++)
	{
		a[i] = n  % 10;
		n = n / 10;
	}
	for(i = 0; i <= m; i++)
	{
		printf("%d", a[i]);
	}
	printf("\n");
	return 0;
}


main()
{
   int i,chang;
   char a[5]={'\0'},b[5]={'\0'};
   scanf("%s",a);
   chang=strlen(a);
   for(i=0;i<chang;i++)
   {
   	b[i]=a[chang-i-1];
   }
   for(i=0;i<chang;i++)
   printf("%c",b[i]);
}


int main()
{
    char num[7];
    gets(num);
    int i;
    for (i=1;i<=strlen(num);i++)
        printf("%c",num[strlen(num)-i]);
    printf("\n");

}


int main()
{
	int n;
	void reverse(int n);
	scanf("%d",&n);
	reverse(n);
	return 0;
}
void reverse(int n)
{
	if(n < 1)
		return;
	printf("%d",n % 10);
	reverse(n / 10);
}


int main(){
	int n,m=0,a=0;
	scanf("%d",&n);
	while(n!=a){
		a=n%10;
		if(a==n)
			break;
		else{
			m=m*10+a*10;
		}
		n=n/10;
	}
	m=m+a;
	printf("%d",m);
	return 0;
}


void main()
{
	int b;
    long n;
	scanf("%d",&n);
	while(n>9)
	{
		b=n%10;
		printf("%d",b);
		n=n/10;
	}
	printf("%d\n",n);
}


int main()
{
	char num[6], i, a, b=0, k=0;
	scanf("%s", num);
	a=strlen(num);
	for(i=0;i<a/2;i++){
		    b = num[i];
		    num[i] = num[a-1-i];
		    num[a-1-i] = b;
		}
	printf("%s", num);
	return 0;
}


int main()
{
int n,m,i=5;
scanf("%d",&n);
if (!n)
{
printf("%d",n);
return 0;
}
while (n)
{
printf("%d",n%10);
n=n/10;
}
return 0;
}


int num,i,c;
int a[5];
void main()
{
 void move(int j,int k);
        scanf("%d",&num);
  if(num>=10000) {c=4;move(num,c);}
  else if(num>=1000) {c=3;move(num,c);}
  else if(num>=100) {c=2;move(num,c);}
  else if(num>=10) {c=1;move(num,c);}
  else {c=0;move(num,c);}
 for(i=0;i<=c;i++)
  printf("%d",a[i]);
}
void move(int j,int k)
{
 if(k>0)
 {
 a[k]=(int)(j/(int)pow(10,k));
 int o=(int)(j%(int)pow(10,k));
    move(o,k-1);
 }
 else if(k==0)
 {a[k]=j;
 }
}


int fun(int a)
{static int b[5],i=0,c=0;
int j,k;
b[i]=a%10;
i++;
a=a/10;
if(a>0) fun(a);
else for(k=0;k<=i;k++)
{for(j=0;j<i-k-1;j++)
b[k]=b[k]*10;
c=c+b[k];}
return (c);
 }
main()
{int n,d;
scanf("%d",&n);
d=fun(n);
printf("%d",d);
return 0;
}


void main()
{
	int num;
	int indiv,ten,hundred,thousand,ten_thousand;
	scanf("%d",&num);
	ten_thousand=num/10000;
	thousand=(num-ten_thousand*10000)/1000;
	hundred=(num-ten_thousand*10000-thousand*1000)/100;
	ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
	indiv=num-ten_thousand*10000-thousand*1000-hundred*100-ten*10;
	if(ten_thousand==0)
	{
		if(thousand==0)
	{
			if(hundred==0)
			{
				if(ten==0)
					printf("%d\n",num);
				else
					printf("%d\n",10*indiv+ten);
			}
				else
					printf("%d\n",100*indiv+10*ten+hundred);
		}
		else
			printf("%d\n",1000*indiv+100*ten+10*hundred+thousand);
	}
	else
		printf("%d\n",10000*indiv+1000*ten+100*hundred+10*thousand+ten_thousand);
}


void main()
{
    char a[6],temp;
	int n,i,j;
	scanf("%s",a);
	n=strlen(a);
	for(i=0,j=n-1;i<j;i++,j--)
	{
		temp=a[i];
	         a[i]=a[j];
		a[j]=temp;
	}
	puts(a);
}


int reverse(int num);

int main()
{
	int n;

	cin >> n;
	cout << reverse(n) << endl;
return 0;
}

int reverse(int num)
{
	int e;
	int n,k;
	int i;
	int s,t;
	int f;
	t=(int)fabs(num);
	if(num<0)
	{
		s=-num;
		f=-1;
	}
	else
	{
	s=num;
	f=1;
	}
	e=(int)log10(t)+1;
	for(i=1;i<e/2+1;i++)
	{
		n=(t%(int)pow(10,i))/(int)pow(10,i-1);
		k=t/((int)pow(10,e-i))-10*(t/((int)pow(10,e-i+1)));
		s-=n*(int)pow(10,i-1);
		s-=k*(int)pow(10,e-i);
		s+=n*(int)pow(10,e-i);
		s+=k*(int)pow(10,i-1);
	}
	return f*s;
}


void main()
{
void nixu(char a[]);
 int i;
 char a[10],c,n;
 gets(a);
 nixu(a);
}
 void nixu(char a[])
 {
 	int m=0,i;
 	char c;
  if(strlen(a)==1) printf("%s",a);
  else
       {
        m=strlen(a);
        c=a[m-1];
            for(i=m-1;i>=1;i--)

                   a[i]=a[i-1];
                   a[0]=c;

                printf("%c",a[0]);
            for(i=0;i<m-1;i++)
            a[i]=a[i+1];
            a[m-1]='\0';
    nixu(a);
  }
 }


void main()
{
	int i=0;
	char n[5];
	while((n[i]=getchar())!='\n')
		i=i+1;
	i=i-1;
	while(i>=0)
	{
		printf("%c",n[i]);
		i=i-1;
}
printf("\n");
}


int main()
{
	int k,i=10,m,n,a;
    scanf("%d",&k);
		n=k;
		for(;;)
		{
			m=n%i;
			n=n/i;
			printf("%d",m);
			if(n==0) break;
		}
}


int main()
{
	char s[6];
	while(scanf("%s",s) != EOF)
	{
		int len = strlen(s);
		for(int i = len - 1;i >= 0;i--)
		{
			printf("%c",s[i]);
		}
		printf("\n");
	}
	return 0;
}


int main()
{
  int n;
  scanf("%d",&n);
  int a=n/10;
  int b=n%10;
  int m=0;
  int t;
  while(a!=0){
  m=b*10;
  t=a;
  a=a/10;
  b=t%10;
  b+=m;
  }
  printf("%d\n",b);
  return 0;

}


int main(){
    int n;
    char word[33];
    scanf("%d",&n);
    for (int i=0;i<n;i++){
         scanf("%s",word);
         if(word[strlen(word)-2]=='e'&&
            word[strlen(word)-1]=='r'){
                  word[strlen(word)-2]='\0';
                  printf("%s\n",word);
         }
         if(word[strlen(word)-2]=='l'&&
            word[strlen(word)-1]=='y'){
                  word[strlen(word)-2]='\0';
                  printf("%s\n",word);
         }
         if(word[strlen(word)-3]=='i'&&
            word[strlen(word)-2]=='n'&&
            word[strlen(word)-1]=='g'){
                  word[strlen(word)-3]='\0';
                  printf("%s\n",word);
         }
    }
return 0;
}


int main()
{
	void crea(char c[]);
	int n,i;
	char a[100][20];

	scanf("%d",&n);

	for(i=0;i<n;i++)
	{
		scanf("%s",a[i]);
	}
	for(i=0;i<n;i++)
	{
		crea(a[i]);
		printf("%s\n",a[i]);
	}
	return 0;
}

void crea(char c[])
{
	int x;
	if(c[(int)strlen(c)-1]=='r') x=0;
	else if(c[(int)strlen(c)-1]=='y') x=1;
	else if(c[(int)strlen(c)-1]=='g') x=2;
	switch(x)
	{
	case 0:c[(int)strlen(c)-1]='\0';c[(int)strlen(c)-1]='\0';break;
	case 1:c[(int)strlen(c)-1]='\0';c[(int)strlen(c)-1]='\0';break;
	case 2:c[(int)strlen(c)-1]='\0';c[(int)strlen(c)-1]='\0';c[(int)strlen(c)-1]='\0';break;
	}
}


int main()
{
	char word[20],newword[20];
	int i,j,len,n;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%s",word);
		len=strlen(word);
		if(word[len-3]=='i'&& word[len-2]=='n'&& word[len-1]=='g')
		{
		   for (j=0;j<len-3;j++)
		   {
              newword[j]=word[j];
		   }
		   newword[j]='\0';
		}
		else
		{
			 for (j=0;j<len-2;j++)
			 {
                newword[j]=word[j];
			 }
		     newword[j]='\0';

		}
		printf("%s\n",newword);
	}
	return 0;
}


int main()
{
 char word[50];
 int n,l;
 scanf("%d", &n);
 for(int i=0; i<n; i++)
 {
  scanf("%s", word);
      l=strlen(word);
     if ((word[l-1]=='r')||(word[l-1]=='y'))
  l=l-2;
  else l=l-3;
     for(int j=0; j<l; j++){
   printf("%c", word[j]);}
  printf("\n");
 }
 return 0;
}


int main(int argc, char* argv[])
{
	int n, wlong;
	char word[32], *p;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%s", word);
		for(p=word; *p; p++);
		switch(*(p-1)){
		case 'r' : wlong=2; break;
		case 'y' : wlong=2; break;
        case 'g' : wlong=3; break;
		}
		*(p-wlong)='\0';
		printf("%s\n", word);
	}
	return 0;}


void delete3(char t[],int length);
void delete2(char t[],int length);

void main()
{
	char word[50][30];
	int n;
	int i,j;
	int length;

	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%s",word[i]);
	}
	for (i=0;i<n;i++)
	{
		length=strlen(word[i]);
		if (word[i][length-1]=='g')
			delete3(word[i],length);
		else
			delete2(word[i],length);
		printf("%s",word[i]);
		if (i!=n-1)
			printf("\n");
	}
}

void delete3(char t[],int length)
{
	t[length-3]='\0';
}

void delete2(char t[],int length)
{
	t[length-2]='\0';
}


int main()
{
int i,j;
int n,l;
 char word[50];
 scanf("%d", &n);
 for(i=0; i<n; i++)
 {
  scanf("%s", word);
      l=strlen(word);
     if ((word[l-1]=='r')||(word[l-1]=='y'))
  l=l-2;
  else l=l-3;
     for(j=0; j<l; j++)
   printf("%c", word[j]);
  printf("\n");
 }
 return 0;
}


int main()
{
	int n,i;
	scanf ("%d",&n);
	for(i=0;i<n;i++){
	int c=0;
	char str[15]={0},string[15]={0};
		scanf("%s",&str);
		c=strlen(str);
		if(str[c-1]=='g'){
		strncpy(string,str,c-3);
		}
		else{
			strncpy(string ,str,c-2);
		}
		printf("%s\n",string);
		}

		return 0;
}


void delsuffix(char main[],int m)
{
	main[strlen(main)-m]='\0';
}
int check(char main[],int len1,char suffix[],int len2)
{
	int n=len1-1,m=len2-1;
	while(m>=0&&main[n]==suffix[m])
	{
		m--;
		n--;
	}
	if(m>=0)
		return 0;
	else
		return 1;
}
void main()
{
	int number,i,lensuffix[3]={2,2,3};
	char s[30],suffix[3][4]={"er","ly","ing"};
	scanf("%d",&number);
	for(i=1;i<=number+1;i++)
	{
		gets(s);
		int m;
		for(m=0;m<3;m++)
		{
			if(check(s,strlen(s),suffix[m],lensuffix[m]))
			{
				delsuffix(s,lensuffix[m]);
				printf("%s\n",s);
				break;
			}
		}
	}
}


void main()
{
	int n,i,k;
	char c[32]="\0";
    scanf("%d",&n);
	for(i=1;i<=n;i++)
	{

		scanf("%s",c);
		char o[32]="\0";
		k=strlen(c);char v[32]="\0";
		strncpy(v,c,k-3); strcat(v,"ing");
		if(strcmp(v,c)==0) {strncpy(o,c,k-3);printf("%s\n",o);}
		else {strncpy(o,c,k-2);printf("%s\n",o);}
    }
}


int main(){
    int n;
    char s[40];
    char local[3][5] = {
         "er", "ly", "ing"
         };
    char res[40];
    scanf("%d", &n);

    while(n--){

         scanf("%s", s);
         int len = strlen(s);
         if(len > 2 && strcmp(s + len - 2, local[0]) == 0){
                for(int i = 0; i < len - 2; ++i){
                        printf("%c", s[i]);
                }
                printf("\n");
         }
         else if(len > 2 && strcmp(s + len - 2, local[1]) == 0){
              for(int i = 0; i < len - 2; ++i){
                        printf("%c", s[i]);
                }
                printf("\n");
         }
         else if(len > 3 && strcmp(s + len - 3, local[2]) == 0){
              for(int i = 0; i < len - 3; ++i){
                        printf("%c", s[i]);
                }
                printf("\n");
         }
         else{
              printf("%s\n", s);
         }
    }

}


void main()
{
	int n,i,j,length;
	char a[100];

	scanf("%d",&n);
	for(j=1;j<=n+1;j++)
	{
		gets(a);
		length=strlen(a);
		if(a[length-3]=='i'&&a[length-2]=='n'&&a[length-1]=='g')
		{
			for(i=0;i<=length-4;i++)
				printf("%c",a[i]);
		        printf("\n");
		}
		else
		{
			for(i=0;i<=length-3;i++)
				printf("%c",a[i]);
		        printf("\n");
		}
	}
}


int main()
{
    char sz[100];
    int n,en;
    scanf("%d",&n);
    for(int i=0;i<=n;i++)
    {
            gets(sz);
            en=strlen(sz);
            switch(sz[en-1])
            {
                            case 'g':
                                 for(int j=0;j<en-4;j++)
                                 printf("%c",sz[j]);
                                 printf("%c\n",sz[en-4]);
                                 break;
                             case 'r':
                                 for(int j=0;j<en-3;j++)
                                 printf("%c",sz[j]);
                                 printf("%c\n",sz[en-3]);
                                 break;
                             case 'y':
                                 for(int j=0;j<en-3;j++)
                                 printf("%c",sz[j]);
                                 printf("%c\n",sz[en-3]);
                                 break;
            }
    }scanf("%d",&n);
            return 0;
}


int main()
{
	int n, i, j;
	char s[100];
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%s", s);
		if(s[strlen(s)-1]=='r' || s[strlen(s)-1]=='y')
		{
			for(j=0;j<strlen(s)-2;j++)
				printf("%c", s[j]);
			getchar();
			printf("\n");
		}
		else
		{
			for(j=0;j<strlen(s)-3;j++)
				printf("%c", s[j]);
			getchar();
			printf("\n");
		}
	}
	return 0;
}


char st[50][33],src[33];
int n,i;
void del();
int main()
{
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
	 scanf("%s",&st[i]);
	 del();
	 printf("%s\n",src);
	 memset(src,0,20);
	}
	return 0;
}
void del()
{
	char str1[3]={'e','r'},str2[3]={'l','y'},str3[4]={'i','n','g'},str[4];
    int len;
	len=strlen(st[i]);
	strcpy(str,st[i]+len-2);
	if (strcmp(str1,str)==0)
		strncpy(src,st[i],len-2);
	else if (strcmp(str2,str)==0)
		strncpy(src,st[i],len-2);
	else {
		strcpy(str,st[i]+len-2);
		if (strcmp(str3,str)==0);
		strncpy(src,st[i],len-3);
	}
	return;
}


int main(int argc, char* argv)
{
    int n;
    char str[30];
    int len;
    scanf("%d",&n);
    while(n-->0)
    {
        scanf("%s",str);
        len = strlen(str);
        switch(str[len - 1])
        {
            case 'r'://er
            case 'y'://ly
                str[len-2] = 0;
                break;
            case 'g'://ing
                str[len-3]=0;
                break;
        }
        printf("%s\n",str);
    }
    return 0;
}


/*
 * homework3.cpp
 *
 *  Created on: 2012-12-4
 *      Author: Lixurong
 */

int main()
{
	int n;
	cin >> n;
	for( int i=0; i<n; i++ )
	{
		char a[40];
		cin >> a;
		if(a[strlen(a)-2]=='e' && a[strlen(a)-1]=='r')
		{
			a[strlen(a)-2]='\0';
		}
		else if(a[strlen(a)-2]=='l' && a[strlen(a)-1]=='y')
		{
			a[strlen(a)-2]='\0';
		}
		else
			a[strlen(a)-3]='\0';
		cout << a;
		if(i!=n-1) cout << endl;
	}
}


int main()
{
	int n,i,j;
	char word[50][30];
	int len[50];
	int a;
	scanf("%d",&n);
    for(i=0;i<n;i++)
	{
		scanf("%s",word[i]);
		len[i]=strlen(word[i]);
	}

	for(i=0;i<n;i++)
	{
		if(word[i][len[i]-1]=='r'||word[i][len[i]-1]=='y') a=2;
		if(word[i][len[i]-1]=='g') a=3;
		for(j=0;j<len[i]-a-1;j++) printf("%c",word[i][j]);
	    printf("%c\n",word[i][len[i]-a-1]);
	}

	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	char s[100];
	int i,len;
	for(i=0;i<n;i++)
	{
		scanf("%s",s);
		len=strlen(s);
		if(s[len-1]=='r'&&s[len-2]=='e')
		{
			s[len-1]=s[len];
			s[len-2]=s[len];
		}
		else if(s[len-1]=='y'&&s[len-2]=='l')
		{
		    s[len-1]=s[len];
			s[len-2]=s[len];
		}
		else
		{
			s[len-1]=s[len];
			s[len-2]=s[len];
			s[len-3]=s[len];
		}
		printf("%s\n",s);
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int n,m,i,j,l;
	char a[50];

	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%s",a);
		l=strlen(a);
		if (a[l-1]=='g') {for (j=0;j<=l-4;j++) printf("%c",a[j]);printf("\n");}
		else {for (j=0;j<=l-3;j++) printf("%c",a[j]);printf("\n");}
	}

	return 0;
}


int main()
{
	int n;
	scanf("%d",&n);
	char string[100][20];
	int i,j;
	for(i=0;i<=n-1;i++)
		scanf("%s",&string[i]);
	int length;
	for(i=0;i<=n-1;i++)
	{
		length=strlen(string[i]);
		if(string[i][length-2]=='e' && string[i][length-1]=='r')
		{
			for(j=0;j<=length-3;j++)
				printf("%c",string[i][j]);
			printf("\n");
		}
		else if(string[i][length-2]=='l' && string[i][length-1]=='y')
		{
			for(j=0;j<=length-3;j++)
				printf("%c",string[i][j]);
			printf("\n");
		}
		else
		{
			for(j=0;j<=length-4;j++)
				printf("%c",string[i][j]);
			printf("\n");
		}
	}
	return 0;
}


int main()
{
int n,m,i,j,k,w;

char sfc[280];
scanf("%d",&n);
for (i=0;i<n;i++) {

scanf("%s",sfc);

if((sfc[strlen(sfc)-3])=='i')sfc[strlen(sfc)-3]=0;
else sfc[strlen(sfc)-2]=0;

printf("%s\n",sfc);
}
return 0;
}


int main(int argc, char* argv[])
{
	int n;
	char word[100];
	char *p;
	int i,len;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{

		memset(word,'\0',sizeof(word));
		p=word;
		scanf("%s",word);
		len=strlen(word);
		p=p+len-2;
		if(*p=='e')
		{
			*p='\0';
			printf("%s\n",word);
		}
		else if(*p=='l')
		{
			*p='\0';
			printf("%s\n",word);
		}
		else
		{
			*(p-1)='\0';
			printf("%s\n",word);
		}
	}

	return 0;
}


int main(int argc, char* argv[])
{
	int n, i, a, j;
	char word[20];
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%s", word);
		a = strlen(word) - 1;
		if(word[a]=='r' || word[a]=='y')
		{
		   word[(a-1)] = '\0';
		}
		if(word[a]=='g')
		{
			word[(a-2)] = '\0';
		}
	   printf("%s\n", word);
	}
	return 0;
}


int main(){
	int n;
	scanf("%d",&n);
	char suoyou[53][35];
	int i;
	for(i=0;i<n;i++){
		scanf("%s",&suoyou[i]);
		if(suoyou[i][strlen(suoyou[i])-1]=='r')
			suoyou[i][strlen(suoyou[i])-2]='\0';
		else if(suoyou[i][strlen(suoyou[i])-1]=='y')
			suoyou[i][strlen(suoyou[i])-2]='\0';
		else if(suoyou[i][strlen(suoyou[i])-1]=='g')
			suoyou[i][strlen(suoyou[i])-3]='\0';
		printf("%s\n",suoyou[i]);
	}
	return 0;
}


void main()
{
	char str[30];
	int n,m,i;
	scanf("%d",&n);
	for(i=0;i<=n;i++)
	{gets(str);
	m=strlen(str);
	if(str[m-1]=='g')
	str[m-3]='\0';
	else
		str[m-2]='\0';
	printf("%s\n",str);
	}
}


int main()
{//declaration
	void del(char*str,int n);
	char word[50][10];
	int n;
	int i;
//input
	scanf("%d",&n);
	for(i=0;i<=n-1;i++)scanf("%s",*(word+i));
//process
	for(i=0;i<=n-1;i++)del(*(word+i),strlen(*(word+i)));
//output
	for(i=0;i<=n-1;i++)printf("%s\n",word+i);
	return 0;
}

void del(char*str,int n)
{//declaration

//process
	if(str[n-2]=='e'&&str[n-1]=='r')str[n-2]='\0';
	if(str[n-2]=='l'&&str[n-1]=='y')str[n-2]='\0';
	if(str[n-3]=='i'&&str[n-2]=='n'&&str[n-1]=='g')str[n-3]='\0';

}


int main()
{
	char str[7][40];
	int n,i,l,j,t;
	scanf("%d\n",&n);
	for(t=0;t<n;t++)
	{
		scanf("%s",str[0]);
		l=strlen(str[0]);

		if(l<=2)
			continue;
		else if(l==3)
		{
			if(str[0][1]=='e'&&str[0][2]=='r'||str[0][1]=='l'&&str[0][2]=='y')
				printf("%c\n",str[0][0]);
		}

			else
		{
			for(i=1;i<7;i++)
				for(j=0;j<40;j++)
					str[i][j]=0;
			strncpy(str[1],str[0],l-3);
			strcpy(str[2],str[1]);
			strcat(str[1],"ing");
			if(strcmp(str[0],str[1])==0)
			{
			printf("%s\n",str[2]);
			continue;
			}

			strncpy(str[3],str[0],l-2);
			strcpy(str[4],str[3]);
			strcat(str[3],"er");
			if(strcmp(str[0],str[3])==0)
			{
				printf("%s\n",str[4]);
				continue;
			}

			strncpy(str[5],str[0],l-2);
			strcpy(str[6],str[5]);
			strcat(str[5],"ly");
			if(strcmp(str[0],str[5])==0)
			{
			printf("%s\n",str[6]);
			continue;
			}
		}

	}
	return 0;
}


void main()
{
	int i,n,t;
	char word[50][20]={'\0'},temp[20]={'\0'};
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%s",word[i]);
	for(i=0;i<n;i++)
	{
		t=strlen(word[i]);
		if(word[i][t-1]=='r'||word[i][t-1]=='y')
		{
			strncpy(temp,word[i],t-2);
			strcpy(word[i],temp);
		}
		else
		{
			strncpy(temp,word[i],t-3);
			strcpy(word[i],temp);
		}
		for(t=0;t<20;t++) temp[t]='\0';
		printf("%s\n",word[i]);
	}
}


int main()
{
int n,k,i;
char word[50][100];
scanf("%d",&n);
for(i=0;i<n;i++){
	scanf("%s",word[i]);}
for(i=0;i<n;i++){
	if((word[i][strlen(word[i])-2]=='e')||(word[i][strlen(word[i])-2]=='l')){
word[i][strlen(word[i])-2]='\0';
}
	else{word[i][strlen(word[i])-3]='\0';}}
for(i=0;i<n;i++){
	printf("%s\n",word[i]);}

	return 0;

	}


int main()
{
	int i,j,n,Strlen;
	char word[100][50];
	scanf("%d",&n);
    for(i=0;i<n;i++)
		scanf("%s",&word[i]);
      for(i=0;i<n;i++)
	  {Strlen=strlen(word[i]);
	  if(word[i][Strlen-1]=='g')
	  for(j=0;j<Strlen-3;j++)
		  printf("%c",word[i][j]);
	  else
       for(j=0;j<Strlen-2;j++)
		  printf("%c",word[i][j]);
	   printf("\n");}
	  return 0;
}


 void main()
{
	char s[20];
	int m,n,i,j,len;
	scanf("%d\n",&n);
	for (i=1;i<=n;i++)
	{
		gets(s);
		len=strlen(s);
		if (s[len-1]=='g') s[len-3]='\0';
		 else s[len-2]='\0';
		puts(s);
	}
}


void main()
{
	char str[35];
	int n,i,l,a,b,c;
	scanf("%d",&n);
	gets(str);
	for(i=0;i<n;i++)
	{
		gets(str);
		l=strlen(str);
		switch (str[l-1])
		{
		case'r':
			for(a=0;a<l-2;a++)
				   printf("%c",str[a]);
			printf("\n");
			break;
		case'y':
			for(b=0;b<l-2;b++)
				   printf("%c",str[b]);
						printf("\n");
			break;
		case'g':
			for(c=0;c<l-3;c++)
				   printf("%c",str[c]);
						printf("\n");
			break;
		}
	}
}


int main()
{
	int n,i,j;
	char word[50];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",word);
		j=strlen(word);
		if(word[j-3]=='i')
		{
			word[j-3]='\0';
		}
		else{
			word[j-2]='\0';
		}
		printf("%s\n",word);
	}
	return 0;
}


int main()
{
	int n,i,len,zzz,m;
	scanf("%d",&n);
	char a[30];
	for(i=0;i<n;i++){
		scanf("%s",a);
		len=strlen(a);
		if(a[len-1]=='g')  zzz=len-4;
		else  zzz=len-3;
		for(m=0;m<=zzz;m++) printf("%c",a[m]);
		printf("\n");
	}

	return 0;
}


void main()
{int n,i,j;char s[100];scanf("%d",&n);
for(i=0;i<n;i++){scanf("%s",s);if(s[strlen(s)-1]=='g')for(j=0;j<strlen(s)-3;j++)printf("%c",s[j]);
else for(j=0;j<strlen(s)-2;j++)printf("%c",s[j]);printf("\n");}}


int main()
{
  char str[100];
  int n,i,d,c,m;
  scanf("%d",&n);
  for(i=0;i<n;i++)
   {
     scanf("%s",str);
     m=strlen(str);
	   c=strlen(str)-2;
	   d=strlen(str)-3;
     if(str[c]=='e'||str[c]=='l' )
        str[c]='\0';
     else if(str[d]=='i')
         str[d]='\0';
     printf("%s\n",str);
  }
   return 0;
}


int main(){
    int n,len;
    scanf("%d",&n);
    char first[50][33];
    for(int a=0;a<n;a++){
        scanf("%s",first[a]);
        len=strlen(first[a]);
        if(first[a][len-1]=='r'){first[a][len-2]='\0';}else
        if(first[a][len-1]=='g'){first[a][len-3]='\0';}else
        if(first[a][len-1]=='y'){first[a][len-2]='\0';}
        printf("%s\n",first[a]);
    }
    return 0;
}


void main()
{
     int n,x,i,j;
     char str[100];
     scanf("%d",&n);
     for(i=1;i<=n+1;i++)
     {gets(str);
      x=strlen(str)-1;
      if(str[x]=='r'||str[x]=='y')
      {str[x-1]='\0'; printf("%s",str);printf("\n");}
      else
      {str[x-2]=0; printf("%s",str);printf("\n");}
     }
}


int main(){
    int N,l,i;
    char a[100];

    scanf("%d",&N);
    while (N--){
        scanf("%s",a);
        l = strlen(a);
        if (strcmp(a + l - 2, "ly") == 0) l-=2;
        if (strcmp(a + l - 2, "er") == 0) l-=2;
        if (strcmp(a + l - 3, "ing") == 0) l-=3;
        for (i=0;i<l;i++) printf("%c",a[i]);
        printf("\n");
    }

    return 0;
}


int main(int argc, char* argv[])
{
	int n, i;
	char ward[20], a;
	scanf("%d", &n);
    for(i=0;i<n;i++){
		scanf("%s", ward);
		a=strlen(ward)-1;
        if((ward[a]=='r')||(ward[a]=='y')){
			ward[a-1]='\0';}
		else{
			ward[a-2]='\0';}
		printf("%s\n", ward);
	}
	return 0;
}


int main(int argc, char* argv[])
{
	int n,i,j;
	struct wordName{
		char name[100];
	}*list,tmp;

	scanf("%d", &n);

	list = (struct wordName *)malloc(sizeof(struct wordName)*n);
	for(i=0;i<n;i++)
	{
		scanf("%s",list[i].name);
	}

	for(i=0;i<n;i++)
	{
		int len = strlen(list[i].name);
		if(list[i].name[len-1]=='g'&&list[i].name[len-2]=='n'&&list[i].name[len-3]=='i')
		{
			list[i].name[len-3]='\0';
		}
		else if(list[i].name[len-1]=='r'&&list[i].name[len-2]=='e')
		{
			list[i].name[len-2]='\0';
		}
		else if(list[i].name[len-1]=='y'&&list[i].name[len-2]=='l')
		{
			list[i].name[len-2]='\0';
		}
	}

	for(i=0;i<n;i++)
	{
		printf("%s\n",list[i].name);
	}

	return 0;
}


  int main(){
   int n,i,len;
   char a[MAX+1];
   scanf("%d",&n);
   for(i=0;i<n;i++){
     scanf("%s",a);
    len=strlen(a);
    if(a[len-1]=='g'){
     a[len-3]='\0';
    }
     else {
      a[len-2]='\0';
     }
   printf("%s\n",a);
    }
   return 0;
}


int main(){
    int n,i,k,j;
    int m;
    scanf("%d",&n);
    char dc[50];
    for(i=0;i<n;i++){
        scanf("%s",dc);
       // printf("%s",dc);
       m=strlen(dc)-1;
     //printf("%d",m);
     if(dc[m]=='g'){
         dc[m-2]=0;
     }
     else dc[m-1]=0;

    printf("%s\n",dc);
    }

}


int main()
{
	int n,z,i,l;
	char word[100];
	scanf("%d",&n);
	for(z=0;z<n;z++)
	{
		scanf("%s",word);
		l=strlen(word);

		for(i=0;i<l;i++)
		{
			if(word[l-3]=='i'&&word[l-2]=='n'&&word[l-1]=='g')
			{
				for(i=0;i<l-3;i++)
					printf("%c",word[i]);
				printf("\n");
				break;
			}
			else
			{
				for(i=0;i<l-2;i++)
					printf("%c",word[i]);
				printf("\n");
				break;

			}
			printf("\n");
		}
	}
	return 0;
}


int main()
{
    int i, j, n, len;
    char word[100];

    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%s", word);
        len = strlen(word);
        if (strcmp(&word[len-2], "er") == 0 || strcmp(&word[len-2], "ly") == 0)
            len -= 2;
        else if (strcmp(&word[len-3], "ing") == 0)
            len -= 3;
        for (j=0; j<len; j++)
            printf("%c", word[j]);
        printf("\n");
    }

    return 0;
}


struct word
{
	char string[30];
};
struct word word[50];

void main()
{
	int n,l,i;
	char temp[30];

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",word[i].string);
	}

	for(i=0;i<n;i++)
	{
		strcpy(temp,word[i].string);
		l=strlen(temp);
		if(temp[l-1]=='g'&&temp[l-2]=='n'&&temp[l-3]=='i')
		{
			temp[l-1]=NULL;
			temp[l-2]=NULL;
			temp[l-3]=NULL;
			strcpy(word[i].string,temp);
		}
		else if(temp[l-1]=='y'&&temp[l-2]=='l')
		{
			temp[l-1]=NULL;
			temp[l-2]=NULL;
			strcpy(word[i].string,temp);
		}
		else if(temp[l-1]=='r'&&temp[l-2]=='e')
		{
			temp[l-1]=NULL;
			temp[l-2]=NULL;
			strcpy(word[i].string,temp);
		}
	}

	for(i=0;i<n;i++)
	{
		printf("%s\n",word[i].string);
	}
}


int main(){
    int i,n,LEN;
	char zfc[51];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",zfc);
		LEN=strlen(zfc);
		switch(zfc[LEN-1]){
		case 'r': zfc[LEN-2]='\0';break;
		case 'y': zfc[LEN-2]='\0';break;
		case 'g': zfc[LEN-3]='\0';break;
		}
		printf("%s\n",zfc);
	}
	return 0;
}


int main()
{
	void cut(char word1[32]);
	char word[50][32];
	int n,k;
	scanf("%d",&n);
	for(k=0;k<n;k++)
	{
		scanf("%s",word[k]);
		cut(word[k]);
		printf("%s\n",word[k]);
	}
}
void cut(char word1[32])
{
	char word2[32]={"0"},word3[32]={"0"},word4[32]={"0"},word5[32]={"0"};
	int m;
	m=strlen(word1);
    strncpy(word3,word1,m-2);
	strcpy(word4,word3);
	strcpy(word5,word3);
    if(strcmp(strcat(word3,"er"),word1)==0||strcmp(strcat(word4,"ly"),word1)==0)
		strcpy(word2,word5);
	else strncpy(word2,word1,m-3);
	strcpy(word1,word2);
}


int main()
{
    int i,j,n,t;
    scanf("%d",&n);
            char w[MAX+1];
        char s[4],a[3];
    for(i=0;i<n;i++)
    {
        int k=0;
        scanf("%s",w);
        for(j=strlen(w)-3;j<=strlen(w);j++)
        {
            s[k]=w[j];
            k++;
        }
        k=0;
         for(j=strlen(w)-2;j<=strlen(w);j++)
         {
             a[k]=w[j];
             k++;
         }
         if(strcmp(a,"er")==0||strcmp(a,"ly")==0)t=2;
         if(strcmp(s,"ing")==0)t=3;
         for(j=0;j<strlen(w)-t;j++)
         printf("%c",w[j]);
         printf("\n");
    }
    return 0;
}


int main()
{
	int n,i,j,l,t;
	char word[50];
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>word;
		l=strlen(word);
		if(word[l-3]=='i'&&word[l-2]=='n'&&word[l-1]=='g')l-=3;
		else if(word[l-2]=='e'&&word[l-1]=='r')l-=2;
		else if(word[l-2]=='l'&&word[l-1]=='y')l-=2;
		for(j=0;j<l;j++)
			cout<<word[j];
		cout<<endl;
	}
	return 0;
}


main()
{
	int n;
	scanf("%d",&n);
	char w[51];
	char *c[]={"er","ly","ing"};
	for(int i=0;i<n;i++)
	{
		scanf("%s",w);
		for(int j=0;j<3;j++)
		{
			int len=strlen(w);
			int slen=strlen(c[j]);
			if(strcmp(c[j],w+len-slen)==0)
			{
				w[len-slen]=0;
				printf("%s\n",w);
				break;
			}
		}
	}
}


int main()
{
	int i,n;
	scanf("%d\n",&n);
	for(i=1;i<=n;i++)
	{char word[32],word1[30]="",c;
	int t;
	scanf("%s",word);
	t=strlen(word);
	c=word[t-1];
    if(c=='g')
	{strncpy(word1,word,t-3);
		printf("%s\n",word1);
	}
	else
	{strncpy(word1,word,t-2);
	printf("%s\n",word1);}
	}
	return 0;
}


char word[100][33];

int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> word[i];
	for(int i=0;i<n;i++)
	{
		int len = strlen(word[i]);
		if(len>2&&word[i][len-2]=='e'&&word[i][len-1]=='r')
		{
			word[i][len-2] = 0;
		}
		else if(len>2&&word[i][len-2]=='l'&&word[i][len-1]=='y')
		{
			word[i][len-2] = 0;
		}
		else if(len>3&&word[i][len-3]=='i'&&word[i][len-2]=='n'&&word[i][len-1]=='g')
		{
			word[i][len-3] = 0;
		}
		cout << word[i] << endl;
	}
}


int main()
{
	int n,len;
	char letter[200];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s",letter);
		len=strlen(letter);
		if(letter[len-2]=='e'&&letter[len-1]=='r')
		{
			letter[len-2]='\0';
			letter[len-1]='\0';
		}
		if(letter[len-2]=='l'&&letter[len-1]=='y')
			{
			letter[len-2]='\0';
			letter[len-1]='\0';
			}
			if( letter[len-3]=='i'&&letter[len-2]=='n'&&letter[len-1]=='g')

			{
				letter[len-3]='\0';
				letter[len-2]='\0';
				letter[len-1]='\0';
			}

				printf("%s\n",letter);

			for(int t=0;t<len;t++)
				letter[t]=' ';

	}
	return 0;
}


void main()
{
	int n,i,t;
	char a[10]={""};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		char b[10]={""};
		scanf("%s",a);
		t=strlen(a);
		switch(a[t-1])
		{
		case'r':strncpy(b,a,t-2);break;
		case'y':strncpy(b,a,t-2);break;
		case'g':strncpy(b,a,t-3);break;
		}
		puts(b);
	}
}


int main()
{
	int n,len;
	char a[1000];
	scanf("%d",&n);

	for(int i=0;i<n;i++)
	{
		scanf("%s",a);
		len=strlen(a);
		if(a[len-1]=='r')
		{
			for(int j=0;j<len-2;j++)
				printf("%c",a[j]);
		}
		printf("\n");
		if(a[len-1]=='y')
		{
			for(int p=0;p<len-2;p++)
				printf("%c",a[p]);
		}
         printf("\n");
		if(a[len-1]=='g')
		{
			for(int q=0;q<len-3;q++)
				printf("%c",a[q]);
		}
        printf("\n");

	}

	return 0;
}


int main()
{
	int n,i,tmp,j;
	char word[100];
    scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",word);
		tmp=strlen(word);
        if(word[tmp-2]=='e'||word[tmp-2]=='l'){
		for(j=0;j<tmp-3;j++){
			printf("%c",word[j]);
		}
		printf("%c\n",word[tmp-3]);
		}
		else{
			for(j=0;j<tmp-4;j++){
			printf("%c",word[j]);
		}
		printf("%c\n",word[tmp-4]);
		}
	}
    return 0;
}


int main()
{
	char input[100];
	int n;
	int len;
	scanf("%d", &n);
//	scanf("\n");
	for(; n>0; n--){
		scanf("%s", input);
		len = strlen(input);
		if ((input[len-2]=='e')&&(input[len-1]=='r'))
			input[len-2] = 0;
		if ((input[len-2]=='l')&&(input[len-1]=='y'))
			input[len-2] = 0;
		if ((input[len-3]=='i')&&(input[len-2]=='n')&&(input[len-1]=='g'))
			input[len-3] = 0;
		puts(input);
	}

	return 0;
}


int main()
{
	int n;
	cin >> n;

	char vocab[36] = {0};
	char suffix[3][6] = {"re", "yl" , "gni"};

	for (int i = 0; i < n; i++)
	{
		memset(vocab,0,36);
		cin >> vocab;

		int k = strlen(vocab) - 1;
		char c[10] = {0};
		int p = 0;

		if (k > 3)
		{
			for (int j = k; j > k - 3; j--)
			{
				c[p] = vocab[j];
				p++;
			}

			if ((strcmp(suffix[2], c) == 0))
			{
				for (int y = k; y > k - 3; y--)
				{
					vocab[y] = '\0';
				}
				cout << vocab << endl;
				continue;
			}

			memset(c,0,3);
			p = 0;

			for (int j = k; j > k - 2; j--)
			{
				c[p] = vocab[j];
				p++;
			}

			if ((strcmp(c,suffix[0]) == 0) || strcmp(c,suffix[1]) == 0)
			{
				for (int y = k; y > k - 2; y--)
				{
					vocab[y] = '\0';
				}
				cout << vocab << endl;
			}

		}
	}

	return 0;
}


void houzhui()
{
  int len;
  char str[32];
  gets(str);
  len=strlen(str);
  if((str[len-2]=='e'&&str[len-1]=='r')||(str[len-2]=='l'&&str[len-1]=='y'))
    str[len-2]='\0';
  if(str[len-3]=='i'&&str[len-2]=='n'&&str[len-1]=='g')
    str[len-3]='\0';
  puts(str);
}

main()
{
      int a,i;
      scanf("%d",&a);
      getchar();
      for(i=0;i<a;i++)
        houzhui();
}


main()
{
	char word[32];
	int n,length;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s",word);
		length=strlen(word);
		if(strcmp(word+length-2,"er")==0||strcmp(word+length-2,"ly")==0)
		word[length-2]='\0';
		else if(strcmp(word+length-3,"ing")==0)
		word[length-3]='\0';
		printf("%s\n",word);
	}
}


void print_str(char* str, int len)
{
	for(int i=0; i<len; i++) {
		cout << str[i];
	}
	cout << endl;
}

int main()
{
	int n, cur_i=0;
	cin >> n;
	while(cur_i < n) {
		cur_i ++;
		char str[300];
		cin >> str;

		int len=strlen(str);
		if(str[len-2] == 'e' && str[len-1] == 'r') {
			print_str(str, len-2);
		} else if(str[len-2] == 'l' && str[len-1] == 'y') {
			print_str(str, len-2);
		} else if(str[len-3] == 'i' && str[len-2] == 'n' && str[len-1] == 'g') {
			print_str(str, len-3);
		} else {
			print_str(str, len);
		}
	}

	return 0;
}


int main()
{
    int i, n, suffixLen;
    char word[32], *p;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {

        scanf("%s", word);

        for (p = word; *p; p++);

        switch (*(p-1))
        {
        case 'r': *(p-2) = '\0';; break;
        case 'y': *(p-2) = '\0';; break;
        case 'g': *(p-3) = '\0';; break;
        }

        printf("%s\n", word);
    }
    return 0;
}


int main(){
	int n;
	char zfc[50][33];
	scanf("%d",&n);
	for(int z=0;z<n;z++){
		scanf("%s",zfc[z]);
		if(zfc[z][strlen(zfc[z])-1]=='g'){
              zfc[z][strlen(zfc[z])-3]='\0';
		}else{
			zfc[z][strlen(zfc[z])-2]='\0';
		}
	}
	for(int x=0;x<n;x++){
		printf("%s\n",zfc[x]);
	}

return 0;
}


int main()
{
	void sh(char c[32]);
	int n,i;
	char c[32];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",c);
		sh(c);
	}
return 0;
}
void sh(char c[32])
{
	int m,j;
    m=strlen(c);
	if(c[m-1]=='y')
	{for(j=0;j<m-2;j++)
	printf("%c",c[j]);
	printf("\n");
	}
	else if(c[m-1]=='r')
	{for(j=0;j<m-2;j++)
	printf("%c",c[j]);
	printf("\n");
	}
	else
	{for(j=0;j<m-3;j++)
	printf("%c",c[j]);
	printf("\n");
	}
}


int main()
{
	char word[max];
	int p,n,i;
	void del(int x,char word[max]);
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s",word);
		p=strlen(word)-1;
		del(p,word);
		printf("%s\n",word);
	}
}

void del(int x,char word[max])
{
	if(word[x]=='g')
		word[x-2]=0;
	else
		word[x-1]=0;
}


void main()
{
	int n,i,j,len;
	char words[50][15];
	scanf("%d\n",&n);
	for (i=0;i<=n-1;i++) gets(words[i]);
	for (i=0;i<=n-1;i++)
	{
		len=strlen(words[i]);
		if (words[i][len-1]=='r'&&words[i][len-2]=='e') len=len-2;
		if (words[i][len-1]=='g'&&words[i][len-2]=='n'&&words[i][len-3]=='i') len=len-3;
		if (words[i][len-1]=='y'&&words[i][len-2]=='l') len=len-2;
		for (j=0;j<=len-1;j++) printf("%c",words[i][j]);
		printf("\n");
	}
}


int main(){
	char str[MAX+1];
	int n,i,j,len;
gets(str);
n=atoi(str);
  for(i=0;i<n;i++){
	  gets(str);
 len=strlen(str);
	 	  if((str[len-2]=='e')&&(str[len-1]=='r'))
					str[len-2]=0;
	  else if((str[len-2]=='l')&&(str[len-1]=='y'))
					str[len-2]=0;
	  else if((str[len-2]=='n')&&(str[len-1]=='g')&&(str[len-3]=='i'))
					str[len-3]=0;
	   puts(str);

  }

	return 0;
}


int main(){
    char sz[500];
    int i,n;
    scanf("%d",&n);
    for (i=0;i<n;i++){
        scanf("%s",sz);
        if (sz[strlen(sz)-1]=='r')  sz[strlen(sz)-2]='\0';
       if (sz[strlen(sz)-1]=='y') sz[strlen(sz)-2]='\0';
       if (sz[strlen(sz)-1]=='g')  sz[strlen(sz)-3]='\0';
      printf("%s\n",sz);
    }
    return 0;
}


void main()
{
	int n,i;
	char word[30];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",word);
		if(!strcmp(word+strlen(word)-2,"er")||!strcmp(word+strlen(word)-2,"ly"))
			word[strlen(word)-2]=0;
		else if(!strcmp(word+strlen(word)-3,"ing"))
			word[strlen(word)-3]=0;
		puts(word);
	}
}


void main()
{
	int n;
	int i,j;
	int tmpl;
	char word[50][50];

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",word[i]);
		tmpl=strlen(word[i]);
		if(word[i][tmpl-1]=='r'||word[i][tmpl-1]=='y')
			word[i][tmpl-2]='\0';
		else if(word[i][tmpl-1]=='g')
			word[i][tmpl-3]='\0';
	}
	for(i=0;i<n;i++)
	{
		printf("%s\n",word[i]);
	}
}