#include<stdio.h>
#define MAX 100000
typedef struct{
  char name[10];
  int time;
} process;

void enqueue(process);
process dequeue(void);

process q[MAX];
int head,tail;


int main(){
  int i,j,t,ct=0;
  process p[MAX],r;
  scanf("%d%d",&i,&t);
  for(j=0;j<i;j++){
    scanf("%s%d",p[j].name,&p[j].time);
    enqueue(p[j]);
  }
  while(head!=tail){
    r=dequeue();
    if(r.time>t){
      r.time -=t;
      enqueue(r);
      ct+=t;
    }
    else if(r.time<=t){
      ct+=r.time;
      printf("%s %d\n",r.name,ct);
    }
}
return 0;
}

void enqueue(process x){
  q[tail]=x;
  tail=(tail+1)%MAX;
}

process dequeue(void){
  process x;
  x=q[head];
  head=(head+1)%MAX;

  return x;
}

