#include<stdio.h>

#define MAX 100005

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

Q data[MAX+1];
int head=0, tail=0, n;

void enqueue(Q);
Q dequeue(void);

int main()
{
  int q, sum_t=0, i;
  Q p;
  
  scanf("%d%d",&n,&q);
  for( i=0 ; i<n ; i++ ){
    scanf("%s%d",data[i].name, &data[i].time);
    enqueue(data[i]);
  }
  i=0;

  while(i!=n){
    p = dequeue();
    if(p.time>q) {
      p.time = p.time-q;
      enqueue(p);
      sum_t += q;
    }
    else{
      sum_t += p.time;
      p.time = sum_t;
      data[i]=p;
      i++;
    }
  }
  for( i=0 ; i<n ; i++ )
    printf("%s %d\n",data[i].name,data[i].time);

  return 0;
}

void enqueue(Q x)
{
  data[tail] = x;
  tail++;
}

Q dequeue(void)
{
  Q x;
  x = data[head];
  head++;
  return x;
}