#include<iostream>
#include<string>
#include<algorithm>
using namespace std;


// 将x 抓化为 m进制 
string get(long x, int m) 
{
	string ans = "";
	int c = 0;
	while( x != 0)
	{
		c = x % m;
		if(c >= 0 && c <= 9) ans += c + '0'; 
		else ans += c + 'A' - 10;
		x /= m;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

// 将a进制的字符串n转化为十进制
long getDecimal(int m, string s) // 15 Aab3 7
{
	long res = 0, t = 0;
	for(int i = 0; i < s.size(); i++){
		char c = s[i];
		if(c >= '0' && c <= '9') t = c - '0';
		else if(s[i] >= 'a' && s[i] <= 'z') t = c - 'a' + 10;
		else t = c - 'A' + 10;
		res = res * m + t;
	}
	return res;
}

 
int main()
{
	int a, b;
	string n;
	
	while(cin >> a >> n >> b)
	{
		long ans = getDecimal(a, n);
		cout << get(ans, b) << endl;
	}	
	return 0;
}