#include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) using namespace std; typedef pair pii; typedef long long int ll; typedef pair pll; int dx[4] = {1,0,0,-1}; int dy[4] = {0,1,-1,0}; #define MOD 1000000007 #define ARRAY_MAX 100005 const int INF = 1e9+7; int main(){ int t,b; cin >> t >> b; for(int i = 0;i < t;i++){ int tmp; cin >> tmp; if(tmp == 0){ cout << "0" << endl; continue; } string s; while(tmp != 0){ int mod = tmp%b; tmp /= b; if(mod < 0){ tmp++; mod -= b; } s.push_back('0'+mod); } //s.push_back('0'+tmp); reverse(s.begin(),s.end()); cout << s << endl; } return 0; }