#include <stdio.h>

#define MAX 100000

typedef struct{
  char name[10];
  int time;
} queue;
  
void enqueue(queue);
queue dequeue(void);

int head=0,tail=0;
queue Q[MAX],t;

int main()
{
  int n,q,i,sum=0;

  scanf("%d%d",&n,&q);

  for(i=0;i<n;i++){
    scanf("%s%d",t.name,&t.time);
    enqueue(t);
  }
  while(head!=tail){
    t=dequeue(); 
    if(t.time>q){
      t.time-=q;
      enqueue(t);
      sum+=q;
    }
    else {
      printf("%s %d\n",t.name,t.time+sum);
      sum+=t.time;
    }
    
  }
  
  return 0;
  
}

void enqueue(queue x){
  Q[tail] = x;
  if(tail+1==MAX) tail=0;
  else tail++;
}

queue dequeue(){
  queue x;
  x=Q[head];
  if(head+1==MAX) head=0;
  else head++;
  return x;
}