#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 100005
#define True 1
#define False 0

typedef struct queue{
  char n[100];
  int s;
} Queue;

int head, tail, n;
Queue  Q[MAX];

int isFull(){
  if(head==(tail+1)%MAX)return True;
  else return False;
}
void enqueue(Queue x){
  if(isFull()==True){
    fprintf(stderr,"Enqueue Error!\n");
    exit(1);
  }
  Q[tail]=x;
  tail=(tail+1)%MAX;
}
Queue dequeue(){
  Queue x=Q[head];

   head=(head+1)%MAX;
   return x;
}
int min(int x, int y){
  if(x<y)return x;
  else return y;
}

int main(){
  int e=0, mint, i, q;
  Queue queue;

  scanf("%d%d",&n,&q);
  for(i=1 ; i<=n ; i++){
    scanf("%s",Q[i].n);
    scanf("%d",&Q[i].s);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    queue=dequeue();
    mint=min(q, queue.s);
    queue.s-=mint;
    e+=mint;
    if(queue.s>0)enqueue(queue);
    else{
      printf("%s %d\n",queue.n, e);
    }
  }
  return 0;
}
