#include<stdio.h>
#include<string.h>
#define LENG 100005
#define MAX 100000
typedef struct aa{
  char name[100];
  int t;
}A;

A Q[LENG+1];
int head, tail, n;
void enqueue(A x){
  if(isFull()){
    printf("error(overflow)");
  }
  Q[tail] = x;
  if(tail+1 == MAX)tail = 0;
  else tail++;
}

A dequeue(){
  A res;
  if(isEmpty()){
    printf("error(underflow)");
  }
  res = Q[head];
  if(head+1==MAX)head = 0;
  else head++;
  return res;
}
int isEmpty(void){
  if(head == tail)
    return 1;
  else return 0;
}
int isFull(void){
  if((head == tail+1)%MAX)
    return 1;
  else return 0;
}
int main(){
  int alg=0,c;
  int i,q;
  A rew;
  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scand("%d",&Q[i].t);
  }
  head=1;
  tail = n+1;
  while(n!=0){
    rew = Q[head];
    rew.t = Q[head].t-q;
    if(rew.t>0){
      alg = alg+q;
      enqueue(rew);
      Q[head] = dequeue();
    }else{
      alg = alg+Q[head].t;
      printf("%s %d\n",rew.name,alg);
      Q[head] = dequeue();
      n--;
    }
  }return 0;
}