#include <iostream>
#include <vector>
using namespace std;
char IntToChar(int x)
{
    if(x>=10)return x-10+'A';
    else
     return x+'0';
}

int CharToInt(char x)
{
    if(x>='0'&&x<='9')
    {
        return x-'0';
    }
    else if(x>='A'&&x<='Z')
    {
        return x-'A'+10;
    }
    else 
    {
        return x-'a'+10;
    }
}
int main() {
    int a, b;
    string str;
    while (cin >> a >>str>> b) { 
        if(str=="0")cout<<"0"<<endl;
        else
        {
            long long ten=0;
            for(int i=0;i<str.size();i++)
            {
                ten*=a;
                ten+=CharToInt(str[i]);
            }
            vector<char> answer;
            while(ten)
            {
                answer.push_back(IntToChar(ten%b));
                ten/=b;
            }
            for(int i=answer.size()-1;i>=0;i--)
            cout<<answer[i];

            cout<<endl;
        }
    }
}