#include <stdio.h>
#include <string.h>
 
typedef struct{
  char name[10];
  int  time;
} Process;

Process dequeue();
void enqueue(Process);
int calc(int,int);
 
Process Q[100000];
int n,q,head,tail;

int main() {
  /* code */
  Process p;
  int min_time=0;
  int sum_time=0;
  int i;
 
  scanf("%d %d\n",&n,&q);
 
  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].time);
  }
 
  head=1;
  tail=n+1;
 
  while(head!=tail){
    p=dequeue();
    min_time=calc(q,p.time);
    p.time-=min_time;
    sum_time+=min_time;
 
    if(p.time>0){
      enqueue(p);
    }else{
      printf("%s %d\n",p.name,sum_time);
    }
  }
  return 0;
}

Process dequeue(){
  Process x;
  x=Q[head];
  if((head+1)>n+1) head=1;
  else            head++;
  return x;
}
 
void enqueue(Process x){
  Q[tail]=x;
  if((tail+1)==n+2)  tail=1;
  else             tail++;
}
 
int calc(int x,int y){
  if(x>=y) return y;
  else     return x;
}