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

typedef struct{
  char name[10];
  int num;
}data;

void enqueue(data);
data dequeue(void);

#define MAX 500000

data dg[MAX];
int head=0,tail,gyo;

int main(){
  int quan;
  int i;
  int rest;
  data dbuf;
  int total=0;
  int cnt=0;
  int buf;
  
  scanf("%d%d",&gyo,&quan);

  for(i=0;i<gyo;i++){
    scanf("%s",dg[i].name);
    scanf("%d",&dg[i].num);
  }

  while(1){
    dbuf=dequeue();
    if(quan<dbuf.num){
      dbuf.num-=quan;
      total+=quan;
    }else {
      buf=dbuf.num;
      dbuf.num-=buf;
      total+=buf;
    }
    if(dbuf.num>0){
      enqueue(dbuf);
    }
    else{
      cnt++;
      printf("%s %d\n",dbuf.name,total);
      if(cnt>=gyo) break;
    }
  }
  
  return 0;
}

void enqueue(data de){
  
  dg[tail]=de;
  if(tail+1==gyo){
    tail=0;
  }else tail++;
}

data dequeue(void){
  int headbuf;
  
  headbuf=head;
  if(head+1==gyo){
    head=0;
  }else head++;

  return dg[headbuf];
}

