#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX 100000
 
void dequeue(char*, int*);
void inqueue(char*, int);
 
char name[MAX][10];
int  time[MAX];
int head=0, tail=1;
 
main(){
  int t=0;
  int i, n, q;
  char tmpName[10];
  int tmpTime;
 
  scanf("%d %d", &n, &q);
  for(i=0; i<n; i++)scanf("%s %d", name[i], &time[i]);
  tail = n;
 
  while(head != tail){
    dequeue(tmpName, &tmpTime);
    if(tmpTime > q){
      t+=q;
      tmpTime -= q;
      inqueue(tmpName, tmpTime);
    }
    else {
      t+=tmpTime;
      printf("%s %d\n", tmpName, t);
    }
  }
  return 0;
}
 
void dequeue(char* tmpName, int* tmpTime){
  strcpy(tmpName, name[head]);
  *tmpTime = time[head];
 
  head = (head+1) % MAX;
}
 
void inqueue(char *tmpName, int tmpTime){
  strcpy(name[tail], tmpName);
  time[tail] = tmpTime;
  
  tail = (tail+1) % MAX;
}