#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
char IntToChar(int n) {
if (n >= 10) {
return n - 10 + 'A';
} else {
return n + '0';
}
}
int CharToInt(char c) {
if (c <= 'f' && c >= 'a') {
return c - 'a' + 10;
} else if (c <= 'F' && c >= 'A') {
return c - 'A' + 10;
} else if (c <= '9' && c >= '0') {
return c - '0';
}
return 0;
}
int main() {
string str,result;
int a, b;
while (cin >> a >> str >> b) {
int sum = 0, k = 1;
for (int i = str.size() - 1; i >= 0; --i) {
sum += k * CharToInt(str[i]);
k *= a;
}
while (sum) {
result = IntToChar(sum % b) + result;
sum /= b;
}
// reverse(result.begin(), result.end());
cout << result << endl;
}
return 0;
}