#include<iostream>
#include<cmath>
#include<algorithm>
int main()
{
    char sys[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    int a, b;
    std::string s, result;
    while(std::cin >> a >> s >> b)
    {
        int sum = 0;
        for(int i = 0;i < s.length();i++)
        {
            if(s[i] >= 'A' && s[i] <= 'F')
            {
                sum += (s[i]-'A'+10)*pow(a, s.length()-1-i);
            }else if(s[i] >= 'a' && s[i] <= 'f')
            {
                sum += (s[i]-'a'+10)*pow(a, s.length()-1-i);
            }else{
                sum += (s[i]-'0')*pow(a, s.length()-1-i);
            }
        }
        result = "";
        while(sum >= b)
        {
            result += sys[sum%b];
            sum /= b;
        }
        result += sys[sum];
        std::reverse(result.begin(),result.end());
        std::cout << result << std::endl;
    }
}