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

#define N 100005

typedef struct {
  char str[10];
  int num;
}Record;

void enqueue(Record);
Record dequeue();

int head = 0, tail = 0, size = 0, n = 0;
Record que[N];


int main () {
  Record quon;
  int q = 0, i, sum = 0;

  scanf("%d %d",&n,&q);
  
  for(i = 0 ; i < n ; i++) {
    scanf("%s",que[i].str);
    scanf("%d",&que[i].num);
  }
  size = n;
  tail = n;

  while(size != 0) {
   
    quon = dequeue();

    if(quon.num - q <= 0) { 
      sum += quon.num;
      printf("%s %d\n",quon.str,sum);
    }
    
    else {
      quon.num = quon.num - q;
      enqueue(quon);
      sum += q;
    }
    
  }
  
  return 0;
}


void enqueue(Record data) {
  que[tail].num = data.num;
  strcpy(que[tail].str,data.str);
  size++;
  if(tail == N) tail = 0;
  else tail++;
}

Record dequeue () {
  int x = 0;
  x = head;
  if(head == N) head = 0;
  else head++;
  size--;
  return que[x];
}

