#include <stdio.h>
#include <string.h>
#define MAX 1000000

typedef struct{
  char name[10];
  int time;
}Queue;
Queue new[MAX];

int main(){
  int n, q, count=0;
  int i, front, rear;
  Queue temp;

  scanf("%d %d",&n, &q);
  for(i = 0 ; i < n ; i++){
    scanf("%s %d",temp.name, &temp.time);
    new[i] = temp;
  }
  front = 0;
  rear = n;
  while(front != rear){
    temp = new[front];
    front++;
    if(temp.time <= q){
      count += temp.time;
      printf("%s %d\n",temp.name, count);
    }else{
      count += q;
      temp.time -= q;
      new[rear] = temp;
      rear ++;
    }
  }
return 0;
}