#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll T, B, N; cin >> T >> B; while(T--){ cin >> N; ll x; string s=""; while(N!=0){ x = N%B; if (x < 0) x -= B; s += char('0'+x); N -= x; N /= B; } if (s == "") s = "0"; reverse(s.begin(), s.end()); cout << s << endl; } return 0; }