import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines T,B,*nums = map(int,read().split()) for n in nums: rep = [] while n: r = n % (-B) n = (n - r) // B rep.append(r) print(''.join(map(str,reversed(rep))))