#include<stdio.h>
#include<stdlib.h>

#define N 100000

typedef struct pp{
  char name[100];
  int time;
}P;

int head=0,tail=0;
P Q[N];

void enqueue(P*,P);
P dequeue(P*);


int main(){
  int i,at=0,t,n,u[N];
  P q;
 
  scanf("%d%d",&n,&t);

  for(i=1;i<=n;i++){
    scanf("%s",&q.name);
    scanf("%d",&q.time);
    enqueue(Q,q);
  }

  while(1){
    q=dequeue(Q);
    if(q.time==-1) break;
    if(q.time<=t){
      at=q.time+at;
      printf("%s %d\n",q.name,at);
    }

    else{
      q.time=q.time-t;
      at+=t;
      enqueue(Q,q);
    }
  }
      
  return 0;
}

void enqueue(P *Q ,P q){
  if(head==(tail+1)%N) exit(1);

  Q[tail]=q;

  if(tail+1==N) tail=0;
  else tail++;
}

P dequeue(P *Q){
  P q;
  
  if(head==tail){
    q.time=-1;
    return q;
  }

  q=Q[head];

  if(head+1==N) head=0;
  else head++;

  return q;
}


