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

typedef struct {
  char name[100];
  int t;
}Process;

Process Q[1000];
int n, head = 0, tail = 0;

void enqueue(Process x){
  Q[tail] = x;

  if(tail == n){
    tail = 1;
  } else {
    tail += 1;
  }

}

Process dequeue(){

  if(head == n){
    head = 1;
  } else {
    head += 1;
  }

  return Q[head-1];

}

int main(){
  int i, q, count = 0, time = 0;
  Process cell;

  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  if(n == 1){
    printf("%s %d\n",Q[0].name ,Q[0].t);
    exit(0);
  }

  for(i = 0; count < n; i++){
    cell = dequeue();

    if(cell.t - q <= 0){
      
      time += cell.t;
      cell.t = 0; 
      printf("%s %d\n",cell.name ,time);
      count++;
    
    } else if(cell.t > 0) {
    
      time += q;     
      cell.t -= q;
      enqueue(cell);
    
    }
    
  }
  return 0;
}