#include using namespace std; typedef long long ll; typedef pair pii; #define pb push_back #define mp make_pair #define rep(i,n) for(int i=0;i<(n);++i) int main(){ cin.tie(0); ios::sync_with_stdio(false); int t,b;cin >> t >> b; int a=abs(b); rep(i,t){ int n;cin >> n; string ans=""; while(n!=0){ if(n%b!=0){ char c='0'; if(n%b>0) c+=n%b; else c+=a+n%b; ans=c+ans; if(n<0) n-=c-'0'; } else{ ans='0'+ans; } n/=b; } cout << ans << endl; } }