#include <stdio.h>
#include <string.h>
#include <math.h>
//下述数字其实就是对应位置的ascii码
int main() {
char arr[64];
long a, b;
while (scanf("%ld %s %ld", &a, arr, &b) != EOF) {
int len = strlen(arr);
long num=0;
//先转化为十进制
for (int i=0;i<len;i++){
int temp = arr[i];
int h;
if (temp>=48 && temp<=57){
h = temp-48;
}else if(temp >=65 && temp <=70){
h = temp-55;
}else {
h = temp-87;
}
long n1 = pow(a, len-i-1)*h;
num+=n1;
}
//再转化为对应进制,取余数的思想
int end=0;
int ret[64]={0};
while (num/b) {
ret[end++] = (num%b);
num/=b;
}
if (num%b!=0){
ret[end++]=num%b;
}
//打印,无营养,不用看
for (int i=end-1;i>=0;i--){
if (ret[i]<10){
printf("%d",ret[i]);
}else {
char cc=ret[i]+55;
printf("%c", cc);
}
}
}
return 0;
}