#本题蕴含思想可用于所有进制转换,即“若任意情况,则以10进制为中介,转10则sum+pow求和,10转则取余并整除” def zs(s): # 字母转数字 return ord(s) - 55 def sz(n): # 数字转字母 return chr(n + 55) def z10(a, n): # a进制n 转 10进制 sum = 0 n = list(str(n)) for k in range(len(n)): if ord(n[k]) in range(97, 123): n[k] = n[k].upper() for i in range(len(n)): if ord(n[i]) in range(65, 91): n[i] = str(zs(n[i])) n.reverse() for j in range(len(n)): sum = sum + pow(int(a), j) * int(n[j]) return sum def tz(b, n): # 10进制的n 转 b进制 a = [] n = int(n) b = int(b) while True: a.append(n % b) n = n // b if n == 0: break for i in range(len(a)): if a[i] > 9: a[i] = sz(a[i]) a.reverse() s = "" for j in range(len(a)): s = s + str(a[j]) return s while True: try: s = list(input().split()) a = s[0] n = s[1] b = s[2] print(tz(b, z10(a, n))) except: break