import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int b = - sc.nextInt(); StringBuilder ans = new StringBuilder(); for (int i = 0; i < t; i++) { boolean isPlus = true; int x = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (x > 0) { if (isPlus) { sb.append(x % b); x /= b; isPlus = false; } else { if (x % b == 0) { sb.append(0); x /= b; } else { sb.append(b - x % b); x /= b; x++; } isPlus = true; } } ans.append(sb.reverse()).append("\n"); } System.out.print(ans); } }