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

#define MAX 100000

int n,head,tail;

typedef struct{
  char name[100];
  int time;
}queue;
queue Q[MAX];

void enqueue(queue);
queue dequeue(void);

int main(){
  int i,quant,t=0,fin=0;
  queue q;

  scanf("%d%d", &n, &quant);
  for(i=1;i<=n;i++) scanf("%s%d", Q[i].name, &Q[i].time);

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

void enqueue(queue q){
  if(tail==n) tail=1;
  else tail++;
  Q[tail]=q;
  return;
}

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