#include <stdio.h>
#define MAX 100000

struct process{
  char name[10];
  int time;
};

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

int head=0,tail=0;
struct process Q[MAX];

int main(){
  int i,n,q,ttime=0;
  struct process p;

  scanf("%d%d",&n,&q);

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

  while(head!=tail){
    p=Q[head];
    dequeue();

    if(p.time<=q){
      ttime+=p.time;
      printf("%s %d\n",p.name,ttime);
    }
    else{
      ttime+=q;
      p.time-=q;
      enqueue(p);
    }
  }
  
  return 0;
}

void enqueue(struct process p){
  Q[tail]=p;
  if(tail+1==MAX) tail=0;
  else tail++;
}

struct process dequeue(){
  struct process p;

  p=Q[head];
  if(head+1==MAX) head=0;
  else head++;

  return p;
}