#include<stdio.h>
#include<string.h>
#define QSIZE 100000

typedef struct list{
  char name[100];
  int t;
}LIST;
LIST queue[QSIZE];
  
int head,tail,n;
LIST dequeue(void);
void enqueue(LIST);

int main(){
  int time = 0;
  int i,q,num;
  LIST data;

  head=1;
  scanf("%d %d",&n,&q);
  tail=n+1;
  
  for(i=1;i<=n;i++){
    scanf("%s", queue[i].name);
    scanf("%d",&queue[i].t);
  }

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

void enqueue(LIST num){
  int next = (tail+1)%QSIZE;
  queue[tail] = num;
  tail =next;
}

LIST dequeue(void){
 LIST val;
  val = queue[head];
  head =(head+1)%QSIZE;
  return val;
}

