import java.util.ArrayDeque; import java.util.Deque; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(), B = scanner.nextInt(); for (int i = 0; i < T; i++) { int N = scanner.nextInt(); Deque a = new ArrayDeque(); do { if (N % B < 0) { a.addFirst(N % B - B); N += B; } else a.addFirst(N % B); N /= B; } while (N != 0); for (int j : a) System.out.print(j); System.out.println(); } } }