#include #define rep(i,n) for(int i=0;i ; const ll INF = 1e18; const int MOD = 1000000007; int b; vector solve(int n){ vector res; while(n != 0){ if(n > 0){ res.push_back(n%(-b)); n -= n%(-b); }else{ res.push_back((-b - (-n)%(-b))%(-b)); n -= (-b - (-n)%(-b))%(-b); } n /= b; } reverse(res.begin(),res.end()); return res; } int main(){ int t; cin >> t >> b; rep(_,t){ int n; cin >> n; vector a = solve(n); rep(i,a.size()) cout << a[i] ; cout << endl; } return 0; }