#include using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);i++) int t,b; int main(){ scanf("%d%d",&t,&b); b = -b; while(t--){ int n; scanf("%d", &n); if(n==0){ puts("0"); continue; } string s; while(n){ int c = n%b; if(c<0)c+=b; if(s.size()%2==0){ s += string(1,'0'+c); n -= c; }else{ c = (b-c)%b; s += string(1,'0'+c); n += c; } n /= b; } reverse(s.begin(), s.end()); puts(s.c_str()); } return 0; }