/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.12 02:51:21 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; vector< int > f(ll n, int b) { vector< int > res; while (n) { res.push_back(n % b); n /= b; } for (int i = 0; i < 10; i++) { res.push_back(0); } return res; } int main() { int t, b; cin >> t >> b; b = -b; for (int _ = 0; _ < t; _++) { ll n; cin >> n; if (n == 0) { cout << 0 << endl; continue; } auto v = f(n, b); ll mod = b; ll total = 0, true_total = 0; vector< int > ans(v.size()); for (int i = 0; i < v.size(); i++, mod *= b) { true_total += v[i] * mod / b; if (i & 1) { for (int j = 0; j < b; j++) { if ((true_total + mod / b * j - total) % mod == 0) { ans[i] = j; total -= mod / b * j; break; } else if (j == b - 1) { } } } else { for (int j = 0; j < b; j++) { if (true_total % mod == (mod / b * j + total) % mod) { ans[i] = j; total += mod / b * j; break; } else if (j == b - 1) { } } } } bool one = false; for (int i = ans.size()-1; i >= 0; i--) { if (ans[i] != 0 || one) { cout << ans[i]; one = true; } } cout << endl; } return 0; }