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

#define MAX 1000

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

queue Q[MAX];
int head,tail;

void enqueue(queue);
queue dequeue(void);

int main(){
  int i,n,Time,sum;
  queue q;

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

  sum = 0;
  head = 0;
  tail = n;

  while(head != tail){
    q = dequeue();
    if(q.time <= Time){
      sum += q.time;
      printf("%s %d\n",q.name,sum);
    }
    else {
      q.time -= Time;
      enqueue(q);
      sum += Time;
    }
  }

  return 0;
}

void enqueue(queue q){

  Q[tail] = q;
  tail++;
}

queue dequeue(){
  queue q;

  q = Q[head];
  head++;
  return q;
}