#include using namespace std; using uint = unsigned int; using lint = long long int; using ulint = unsigned long long int; template using V = vector; template using VV = V< V >; template void assign(V& v, int n, const U& a) { v.assign(n, a); } template void assign(V& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); } int emod(int x, int p) { return (x % p + p) % p; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int t, b; cin >> t >> b; while (t--) { int n; cin >> n; string res; while (n) { res += '0' + emod(n, -b); n = (n - emod(n, -b)) / b; } reverse(begin(res), end(res)); cout << res << '\n'; } }