#include<iostream> #include<cstdio> #include<string> using namespace std; int CharToInt(char x){ if(x>='a'&&x<='f'){ return x-'a'+10; } else 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 a,b; string n; while(cin>>a>>n>>b){ if(n=="0"){ printf("0"); } else{ long number=0; for(int i=0;i<n.size();++i){ number*=a; number+=CharToInt(n[i]); } string resultant; while(number!=0){ resultant+=IntToChar(number%b); number/=b; } for(int i=resultant.size()-1;i>=0;--i){ printf("%c",resultant[i]); } } printf("\n"); } return 0; }