list_num=['A','B','C','D','E','F'] while True: try: list1=list(input().strip().split()) a,n,b=int(list1[0]),str(list1[1]),int(list1[2]) list2=[] n1=n.upper() sum=0 for i in range(len(n1)): if '0'<=n1[i]<='9': sum+=a**(len(n1)-i-1)*int(n1[i]) else: sum+=a**(len(n1)-i-1)*(list_num.index(n1[i])+10) while sum>0: list2.append(sum%b) sum//=b list2.reverse() for i in range(len(list2)): if 0<=list2[i]<=9: print(list2[i],end="") else: print(list_num[list2[i]-10],end="") print() except EOFError: break