#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

//习题6.4 数制转换 
int CharToInt(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    else if (c >= 'a' && c <= 'f') {
        return c - 'a' + 10;
    }
    else{
        return c - 'A' + 10;
    }
}

char IntToChar(int n) {
    if (n >= 0 && n <= 9) {
        return n + '0';
    }
    else {
        return n - 10 + 'A';
    }
}

int main()
{
    //a,n,b 
    //15 Aab3 7
    int a, b;
    string s;
    while (cin >> a >> s >> b) {
        long num = 0;
        for (int i = s.size() - 1; i >= 0; i--) {
            num += CharToInt(s[i]) * pow(a, s.size() - 1 - i);
        }
        //cout << num << endl;
        string res = "";
        while (num != 0) {
            res += IntToChar(num % b);
            num /= b;
        }
        reverse(res.begin(), res.end());
        cout << res << endl;
    }

    return 0;
}

// 64 位输出请用 printf("%lld")