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

int isEmpty(void);
void enqueue(int);
int dequeue(void);
int calc(void);

int time[N];
int head=0,tail=0;

int main(){
  
  int i;
  int n,q;
  int totaltime=0;
  char swap[10],s[N][10];
  
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",s[i],&time[i]);
    tail++;
  }
  while(isEmpty()!=1){
    if(time[head]<=q){
      totaltime+=dequeue();
      printf("%s %d\n",s[head-1],totaltime);
    }
    else{
      strcpy(swap,s[head]);
      strcpy(s[tail],swap);
      time[head]-=q;
      enqueue(dequeue());
      totaltime+=q;
    }
  }
  return 0;
}

int isEmpty(){
  if(head==tail) return 1;
  return 0;
}

void enqueue(int n){
  
  time[tail]=n;
  if(tail+1==N){
    tail=0;
  }
  else{
    tail++;
  }
}

int dequeue(){

  int n;

  n=time[head];
  if(head+1==N){
    head=0;
  }
  else{
    head++;
  }
  return n;
}

