#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
string st;
int n, m, s = 0, a, b[32] = {}, j = 0;
cin >> n >> st >> m;
for (int i = 0; i < st.size(); i++)
{
if (st[i] >= 'A' && st[i] <= 'F')
{
a = st[i] - 'A' + 10;
}
else
{
a = st[i] - '0';
s = s * n + a;
}
}
while (s)
{
int k = s % m;
b[j++] = k;
s /= m;
}
for (int i = j - 1; i >= 0; i--)
{
if (b[i] < 10)
cout << b[i];
else
printf("%c", b[i] - 10 + 'A');
}
cout << endl;
return 0;
}