#include using namespace std; // g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main // g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main using ll = long long; using vi = vector; using vl = vector; using vll = vector; using vii = vector; using pii = pair; using vc = vector; using vcc = vector; using vb = vector; using vbb = vector; using pll = pair; using pli = pair; using vd = vector; using vdd = vector; #define REP(i,n) for(int (i)=0;(i)<(n);(i)++) #define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++) #define MAX(a, b) ((a > b) ? a : b) #define MIN(a, b) ((a > b) ? b : a) int gcd(int a,int b){return b?gcd(b,a%b):a;} int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; const int MOD = 1e9 + 7; vector prime_factorization(int n){ // 素因数分解をしたvector<素数, 指数>を返す vector res; int tmp, root_n = floor(sqrt(n)); if(n % 2 == 0){ tmp = 1; n /= 2; while(n % 2 == 0){ n /= 2; tmp++; } res.push_back(make_pair(2, tmp)); } ll i = 3; while(i <= root_n && i <= n){ if(n % i == 0){ tmp = 1; n /= i; while(n % i == 0){ n /= i; tmp++; } res.push_back(make_pair(i, tmp)); } i += 2; } if(n != 1) res.push_back(make_pair(n, 1)); return res; } vector prime_factorization(ll n){ // 素因数分解をしたvector<素数, 指数>を返す vector res; int tmp, root_n = floor(sqrt(n)); if(n % 2 == 0){ tmp = 1; n /= 2; while(n % 2 == 0){ n /= 2; tmp++; } res.push_back(make_pair(2, tmp)); } ll i = 3; while(i <= root_n && i <= n){ if(n % i == 0){ tmp = 1; n /= i; while(n % i == 0){ n /= i; tmp++; } res.push_back(make_pair(i, tmp)); } i += 2; } if(n != 1) res.push_back(make_pair(n, 1)); return res; } // n は 2以上の素数表を返す vb Primes(int n){ vector res(n + 1, true); res.at(0) = false; res.at(1) = false; for(int i = 2; i <= sqrt(n); i++){ if(res.at(i)){ for(int j = 2 * i; j <= n; j += i){ res.at(j) = false; } } } return res; } // =================================================== class m_digit{ public: m_digit(int d); ~m_digit(); std :: string turn_to_new_digit(int k); void warizan(int x, int &q, int &r); private: int decimal; unsigned int abs_decimal; }; m_digit :: m_digit(int d){ decimal = d; abs_decimal = abs(d); } m_digit :: ~m_digit(){} // d = qx + r : 0 <= r < x void m_digit :: warizan(int x, int &q, int &r){ if(x == 0){q = 0; r = 0;} else if(x < 0){ int xx = -x; q = (xx / abs_decimal); r = xx % abs_decimal; if(r != 0){ q++; r = abs_decimal - r; } } else{ q = -(x / abs_decimal); r = x % abs_decimal; } } std :: string m_digit :: turn_to_new_digit(int k){ std :: string res = ""; int r; while(k != 0){ // cout << "k = " << k << ", r = " << r << "\n"; warizan(k, k, r); res = (char)('0' + r) + res; } return res; } int main(){ int t, b; cin >> t >> b; m_digit solve(b); vi data(t); REP(i, t) cin >> data.at(i); REP(i, t){ cout << solve.turn_to_new_digit(data.at(i)) << "\n"; } return 0; }