#include int T, B, N; char ans[1000]; int main(void) { scanf("%d %d", &T, &B); for (int _ = 0; _ < T; _++) { scanf("%d", &N); if (N == 0) { puts("0"); continue; } int k = 900; while (N != 0) { int r = N % B; if (r < 0) r -= B; ans[--k] = r + '0'; N -= r; N /= B; } puts(&ans[k]); } return 0; }