#include <stdio.h>
#include <stdlib.h>
#define LEN 100005
#define FALSE -1

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

P Q[LEN+1];
int head=1, tail=1, n;

void enqueue(P x){
  if(isFull()==FALSE){
    fprintf(stderr,"full\n");
    exit(1);
  }
  Q[tail]=x;
  if((tail+1)==LEN)
    tail=0;
  else 
    tail++;
}

P dequeue(){
  P a;
  if(isEmpty()==FALSE){
    fprintf(stderr,"empty\n");
    exit(2);
  }
  a=Q[head];
  if((head+1)==LEN)
    head=0;
  else 
    head++;
  return a;
}

int isEmpty(){
  if(head==tail)return FALSE;
  else return 0;
}
int isFull(){
  if(head==(tail+1)%LEN)return FALSE;
  else return 0;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    tail++;
  }
  i=0;
  while(i!=n){
   u=dequeue();
   c=u.t-q;
   if(c>0){
     u.t=c;
     enqueue(u);
     elaps+=q;
   }
   else{
     elaps+=u.t;
     printf("%s %d\n",u.name,elaps);
     i++;
   }

  }
  
  return 0;
}

