#include <stdio.h>

#define MAX 1000000

typedef struct pp{
  char name[10];
  int time;
}P;

int head=0, tail=0;
P Q[MAX], a;

void enqueue(P);
P dequeue(void);

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

  scanf("%d%d", &n, &q);
  
  for(i = 0 ; i < n ; i++){
    scanf("%s%d", a.name, &a.time);
    enqueue(a);
  }
  
  while(head != tail){
    a = dequeue();
    if(a.time > q){
      a.time -= q;
      enqueue(a);
      sum += q;
    }
    else{
      printf("%s %d\n", a.name, a.time+sum);
      sum += a.time;
    }
  }
  
  return 0;
}

void enqueue(P x)
{
  Q[tail] = x;
  if (tail + 1 == MAX){
    tail = 0;
  }
  else{
    tail++;
  }
}

P dequeue()
{
  P x;
  x = Q[head];
  if (head + 1 == MAX){
    head = 0;
  }
  else{
    head++;
  }
  return x;
}