#include<iostream> #include<cstdio> #include<string> #include<vector> using namespace std; int CharToInt(char x){ if(x<='9'){ return x-'0'; } else{ return x-'A'+10; } } char IntToChar(int x){ if(x<=9){ return x+'0'; } else{ return x-10+'a'; } } int main(){ int M,N; string number; while(scanf("%d%d",&M,&N)!=EOF){ cin>>number; long long decimal=0; for(int i=0;i<number.size();++i){ decimal*=M; decimal+=CharToInt(number[i]); } vector<char> resultant; while(decimal!=0){ resultant.push_back(IntToChar(decimal%N)); decimal/=N; } for(int i=resultant.size()-1;i>=0;--i){ printf("%c",resultant[i]); } printf("\n"); } return 0; }