#include<stdio.h>
int main(){
int a,b=0,i,n,q,T=0;
int Time[n];
char name[n][10];
scanf("%d%d",&n,&q);
for(i=0;i<n;i++){
scanf("%s%d",name[i],&Time[i]);
}
while(1){
if(Time[0]<0)break;
    if((Time[0])-q<=0){
      n--;
      T=T+q;
printf("%s %d\n",name[b],T);

for(i=n;i>0;i--){
if(b==4)b=0;
else b++;
a=Time[i-1];
Time[i-1]=Time[i];
Time[i]=a;
}
}
    else{
      T=T+q;
    for(i=n;i>0;i--){
    a=Time[i-1];
    Time[i-1]=Time[i];
    Time[i]=a;
    }
    }
  }
  return 0;
}

