nums = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n, b = map(int,input().split())
ans = ''
while n:
ans = nums[n % b] + ans
n //= b
print(ans)
nums = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n, b = map(int,input().split())
ans = ''
while n:
ans = nums[n % b] + ans
n //= b
print(ans)