#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define int long long
#define for(x,y,k) for(int i=x;i<=y;i+=k)
int n;
inline int read(){
int x=0,f=1;
char ch=getchar();
if(ch=='-')f=-1;
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
int jjb(int a){
int res=1;
while(a--)res*=n;
return res;
}
using namespace std;
const int N=0;
signed main(){
ios::sync_with_stdio(0);
n=read();
string s;
cin>>s;
int m=read();
reverse(s.begin(),s.end());
int sum=0;
for(0,s.size()-1,1){
if(s[i]>'A'&&s[i]<'Z')sum+=(s[i]-'A'+10)*jjb(i);
else sum+=(s[i]-'0')*jjb(i);
}
string res;
while(sum!=0){
char t;
if(sum%m>9)t=sum%m-10+'A';
else t=sum%m+'0';
res.push_back(t);
sum/=m;
}
cout<<res;
return 0;
}
为什么RE