#include #include #include using namespace std; int T, B; void mdiv(int n, int b, int &q, int &r) { if(n > 0){ q = n/b; r = n%b; q *= -1; } else{ int m = (-n+b-1)/b*b; q = m/b; r = m+n; } } int main(void) { cin >> T >> B; for(int t = 0; t < T; t++){ int n; cin >> n; string ans; while(n != 0){ int q, r; mdiv(n, -B, q, r); ans += r + '0'; n = q; } reverse(ans.begin(), ans.end()); cout << ans << endl; } return 0; }