#include<stdio.h>
#include<string.h>
#define N 100001
int main(){
  int n,q,i,j,Time[N],end=0,head=0,tail=0,k=0,sumtime=0;
  char name[N][11];
  scanf("%d%d",&n,&q);
  tail=n;
  
  for(i=0;i<n;i++){
    scanf("%s%d",name[i],&Time[i]);
  }
  while(1){
    if(n==end)
      break;
    if(Time[head]<=q&&Time[head]!=0){
      printf("%s %d\n",name[head],sumtime+Time[head]);
      sumtime+=Time[head];
      Time[head]=0;
      head++;
      if(head==N)
	head=0;
      end++;
    }
    else{
      Time[head]-=q;
      sumtime+=q;
      strcpy(name[tail],name[head]);
      Time[tail++]=Time[head];
      if(tail==N)
	tail=0;
      head++;
      if(head==N)
	head=0;
    }

  }

  return 0;
}

