#include using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);i++) int t,b; string rev[12525]; int main(){ scanf("%d%d",&t,&b); b = -b; REP(v,125252){ int ev = 0; string s; int bb = 1; int x = v; while(x>0){ int c = x % b; x /= b; ev += bb * c; bb *= -b; s = string(1,c+'0') + s; } if(ev<0 || ev>=12525)continue; rev[ev] = s; } while(t--){ int n; scanf("%d",&n); puts(rev[n].c_str()); } return 0; }