#include #define FOR(v, a, b) for(int v = (a); v < (b); ++v) #define FORE(v, a, b) for(int v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for(int v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c,x) ((c).find(x) != (c).end()) #define LLI long long int #define fst first #define snd second #ifdef DEBUG #include #define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl; #else #define dump(x) #endif using namespace std; template using V = vector; template using P = pair; template void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost< istream& operator>>(istream &is, vector &v){for(auto &a : v) is >> a; return is;} template istream& operator>>(istream &is, pair &p){is >> p.first >> p.second; return is;} template ostream& operator<<(ostream &os, const vector &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;} template ostream& operator<<(ostream& os, const pair &p){os << "(" << p.first << "," << p.second << ")"; return os;} template T& chmin(T &a, const T &b){return a = min(a,b);} template T& chmax(T &a, const T &b){return a = max(a,b);} string minus_base(int n, int base){ string ret; if(n == 0) ret.push_back('0'); while(n != 0){ int r = n%abs(base); if(r<0) r += abs(base); n = (n-r)/base; ret.push_back('0'+r); } reverse(ALL(ret)); return ret; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int T,B; cin >> T >> B; REP(i,T){ int N; cin >> N; auto ans = minus_base(N, B); cout << ans << endl; } return 0; }