#include <cstdio>#include <cstring>#include <stack>usingnamespacestd;
#define N 30intmain()
{
charinput[N];
inta, b;
inti;
intlenOfInput;
intsum;
intc;
stack<int>s;
charres[N];
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifwhile (scanf("%s%d%d", input, &a, &b) ==3) {
lenOfInput=strlen(input);
for (i=0, sum=0; i<lenOfInput; i++) {
if (input[i] >='0'&&input[i] <='9')
c=input[i] -'0';
elsec=input[i] -'A'+10;
sum=sum*a+c;
}
if (sum==0) {
printf("%7s\n", "0");
continue;
}
while (sum) {
s.push(sum%b);
sum/=b;
}
c=0;
while (!s.empty()) {
i=s.top();
s.pop();
if (i>=10)
res[c++] =i-10+'A';
elseres[c++] =i+'0';
}
res[c] ='\0';
if (c>7)
printf("%7s\n", "ERROR");
elseprintf("%7s\n", res);
}
return0;
}