#include <iostream>
#include <cmath>
using namespace std;
int charToInt(char c) {
    if (c >= 'a' && c <= 'f') return c - 'a' + 10;
    else if (c >= 'A' && c <= 'F') return c - 'A' + 10;
    else return c - '0';
}
char intToChar(int a) {
    if (a >= 10 && a <= 15) return char(a - 10 + 'A');
    else return char(a + '0');
}
int toDec(string any, int a) {
    long long ans = 0;
    for (int i = any.size() - 1; i >= 0; i--) {
        ans += charToInt(any[i]) * pow(a, any.size() - 1 - i);
    }
    return ans;
}
string toAny(long long n,int b){
string ans;
if(n==0) ans="0";
while(n!=0){
    ans=intToChar(n%b)+ans;
    n/=b;
}
return ans;
}
int main() {
    int a;
    while (cin >> a) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        string n;
        int b;
        cin >> n>>b;
        cout<<toAny(toDec(n,a),b)<<endl;
    }
}
// 64 位输出请用 printf("%lld")