T, B = map(int,input().split()) N = [int(input()) for l in range(T)] plusB = -B for t in N: a = [] sign = 1 while t != 0: if sign > 0: a.append(t % plusB) t = (t - a[-1]) / plusB else: a.append(-t % plusB) t = (t +a[-1]) / plusB sign *=-1 print(''.join(map(str,map(int,a[::-1]))))