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 = [] if not n: print(0) continue while n: r = n % (-B) n = (n - r) // B rep.append(r) print(''.join(map(str,reversed(rep))))