#include <stdio.h> #include <string.h> #include <map> #include <algorithm> #include <ctype.h> using namespace std; map<char, int> p; map<int, char> q; int a, b; char n[1000]; void init() { for (int i = 0; i < 6; i++) { p['A' + i] = 10 + i; p['a' + i] = 10 + i; } for (int i = 0; i < 10; i++) q[i] = '0' + i; for (int i = 0; i < 6; i++) q[10 + i] = 'A' + i; } int toDemical(char* num) { int sum = 0; int len = strlen(num); for (int i = 0; i < len; i++) { if ( isdigit(num[i]) ) sum = sum * a + num[i] - '0'; else sum = sum * a + p[num[i]]; } return sum; } void toB(int d) { if ( d / b > 0 ) toB( d / b ); printf("%c", q[d % b]); } int main() { // freopen("1.txt", "r", stdin); init(); while ( scanf("%d%s%d", &a, n, &b) == 3 ) { int tmp = toDemical(n); toB(tmp); printf("\n"); } return 0; }