#include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int t, b; cin >> t >> b; b *= -1; char c[256] = {}; for (int h = 0; h < t; h++) { int n; cin >> n; int i = 255; c[i] = 0; while (n) { int r = n % b; if (r < 0) n -= b, r += b; c[--i] = r + '0'; n /= -b; } cout << c + i << '\n'; } return 0; }