#include<cstdio>
#include<cmath>
#include<map>
#include<stack>
using namespace std;
int main(){
int a,b;
char s[20];
while (scanf("%d %s %d", &a, &s, &b) != EOF){
stack<int> hhh;
map<char, int>mymap = {
{ '0', 0 }, { '1', 1 }, { '2', 2 },
{ '3', 3 }, { '4', 4 }, { '5', 5 },
{ '6', 6 }, { '7', 7 }, { '8', 8 },
{ '9', 9 }, { 'a', 10 }, { 'b', 11 },
{ 'c', 12 }, { 'd', 13 }, { 'e', 14 },
{ 'f', 15 }, { 'A', 10 }, { 'B', 11 },
{ 'C', 12 }, { 'D', 13 }, { 'E', 14 },
{ 'F', 15 }
};
int k = -1;
for (int i = 0; s[i] != '\0'; i++){
k++;
}
long num=0;
for (int i = 0; s[i] != '\0'; i++){
num = num+mymap[s[i]] * pow(a, k);
k--;
}
while (num != 0){
int p = num%b;
hhh.push(p);
num=num/b;
}
while (!hhh.empty()){
if (hhh.top() >= 0 && hhh.top() <= 9){
printf("%d", hhh.top());
}
else if (hhh.top() == 10){
printf("A");
}
else if (hhh.top() == 11){
printf("B");
}
else if (hhh.top() == 12){
printf("C");
}
else if (hhh.top() == 13){
printf("D");
}
else if (hhh.top() == 14){
printf("E");
}
else if (hhh.top() == 15){
printf("F");
}
hhh.pop();
}
printf("\n");
}
}