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

int head = 0;
int tail = 0;
char name[1000000][11];
int timea[1000000];

int main(){
  int n ,q,i,j,count = 0;
  scanf("%d%d",&n,&q);

  for(tail=0;tail<n;tail++){
    scanf("%s%d",name[tail],&timea[tail]);
  }

  while(head!=tail){
    if(q < timea[head]){
      timea[tail] = timea[head]-q;
      strcpy(name[tail],name[head]);
      count += q;
      tail = (tail + 1)%1000000;
      head = (head + 1)%1000000;
    }
    else{
      count += timea[head];
      printf("%s %d\n",name[head],count);
      head = (head + 1)%1000000;
    }
  }

  return 0;
}

