#include #include using namespace std; void ins() {} templatevoid ins(T& v,Rest&... rest){cin>>v;ins(rest...);} #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) int main() { int T, B; ins(T, B); stack st; rep(i, T) { int a; cin >> a; if (a == 0) { cout << 0 << endl; continue; } while (a != 0) { int r = a % (-B); if (r < 0) r -= B; st.push(r); a -= r; a /= B; } while (!st.empty()) { cout << st.top(); st.pop(); } cout << endl; } return 0; }