#include using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int T, B; cin >> T >> B; for (int i = 0; i < T; i++) { ll n; cin >> n; string ans = ""; while (n != 0) { int d = ((n % -B) - B) % -B; n -= d; ans += (char)('0' + d); n /= B; } reverse(ans.begin(), ans.end()); cout << ans << endl; } return 0; }