#include<stdio.h>
#include<string.h>

typedef struct {
 char name[100];
 int t;
} process;

process array[100001];
int head=0,tail=0;

int main(void){
 int n,q,i,sum=0,endprocess=0;
 scanf("%d %d",&n,&q);
 for(i=0;i<n;i++){
  scanf("%s %d",array[i].name,&array[i].t);
 }
 while(endprocess!=n){
  if(q<array[head].t){
   array[head].t=array[head].t-q;
   sum+=q;
   array[tail]=array[head];
   if(tail==n-1) tail=0;
   else tail++;
  }
  else if(array[head].t!=0){
   sum+=array[head].t;
   array[head].t=0;
   printf("%s %d\n",array[head].name,sum);
   endprocess++;
  }
  if(head==n-1) head=0;
  else head++;
 }
 return 0;
}