#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; if (n == 0) { cout << "0\n"; continue; } int i = 255; c[i] = 0; while (n) { int r = n % b; if (r < 0) r += b; n -= r; n /= -b; c[--i] = r + '0'; } cout << c + i << '\n'; } return 0; }