#include using namespace std; int main() { int t, b; cin >> t >> b; for (int ti = 0; ti < t; ti++) { int n; cin >> n; deque v; while (n) { int c = (n % b < 0) ? (n % b + abs(b)) : (n % b); n -= c; v.push_front(c); n /= b; } for (int i = 0; i < v.size(); i++) { cout << v[i]; } cout << endl; } }