#include <stdio.h>
#include <string.h>
#define N 100
int dequeue(void);
void enqueue(int);
int tim=0,i,n,q,pnumber[N],head=0,tail;
char pname[N][10];
int main(){
  int x; 
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++) scanf("%s%d",pname[i],&pnumber[i]);
  tail=n;
  while(1){
    if(head==tail)break;
   
    x= dequeue();
    if(x>q){ 
      tim+=q;
      enqueue(x-q);
    }
    else{
      tim+=x;
        
      printf("%s %d\n",pname[head-1],tim);
    }

  }


  return 0;
}

int dequeue(void){
  int x;
  x = pnumber[head];
if (head + 1 == N)
    head = 0;
  else head = head + 1;
 return x;

}
void enqueue(int x){
  pnumber[tail] = x;
  strcpy( pname[tail],pname[head-1]) ;
if(tail + 1 == N)
    tail = 0;
  else tail = tail + 1;
}