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

#define LENGTH 100005



typedef struct {
  char name[100];
  int time;
}Process;

void enqueue(Process);
Process dequeue(void);

Process queue[LENGTH];
int head=0,tail=0;


int main(){
  Process data;
  int num,qms,count=0,lap,i;

  scanf("%d%d",&num,&qms);

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

  while(head!=tail){
    data=dequeue();
    lap=data.time<qms ? data.time : qms;
    count+=lap;
    data.time-=lap;
    if(data.time>0) enqueue(data);
    else printf("%s %d\n",data.name,count);
  }
  return 0;
}

void enqueue (Process data){
  int next;
  next=(tail+1)%LENGTH;
  
  if(next==head) exit(2);
  queue[tail].time=data.time;
  strcpy(queue[tail].name,data.name);
  tail=next;
}

Process dequeue(){
  Process data;
  if(head==tail) exit(3);
  data.time=queue[head].time;
  strcpy(data.name,queue[head].name);
  head=(head+1)%LENGTH;
  return data;
}
      
    
  

