#include using namespace std; const static inline void rec(int data, int base) { if(data == 0) return; int next = abs(data) % base; if(data < 0) next = (base - next) % base; rec((data - next) / -base, base); cout << next; } int main() { int T, B; cin >> T >> B; while(T--) { int N; cin >> N; if(N == 0) { cout << "0\n"; continue; } rec(N, -B); cout << endl; } }