#include <iostream> #include <cstring> #include <vector> using namespace std; int char2int(char x){ if(x>='a'&&x<='f') return x-'a'+10; else if(x>='A'&&x<='F') return x-'A'+10; else if(x>='0'&& x<='9') return x-'0'; else return -1; } char int2char(int x){ if(x>=0 && x<=9) return x+'0'; else return x-10+'A'; } int main() { int b1,b2; string x; while(cin>>b1>>x>>b2){ long long n=0; int i=0; while(x[i]=='0') i++; while(i<x.length()){ n=n*b1+char2int(x[i]); i++; } vector<char> arr; if(n==0) { cout<<n<<endl; continue;} while(n>0){ arr.push_back(int2char(n%b2)); n/=b2; } for(int i=arr.size()-1;i>=0;i--) cout<<arr[i]; cout<<endl; } }