#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct qeu{
  int n;
  char name[10];
}Qeu;
void init();
void enque(Qeu);
Qeu deque();

int head,tail;
Qeu Qo[100000];

void init(){
  head = 0;
  tail = 0;
}

void enque(Qeu Q){
  Qo[tail++] = Q;
  tail = tail % 100000;
}

Qeu deque(){
  head++;
  if(head == 100000){
    head = 0;
    return Qo[99999];
  }
  else
    return Qo[head-1];
}

int mini(int a,int b){
  if(a<b) return a;
  else return b;
}
  
int main(){
  Qeu Q[1000],Qt[1000],Qnow;
  int i,n,time;
  int total,tt;
  int count =0 ;
  total = 0;
  scanf("%d %d",&n,&time);

  for(i=0;i<n;i++){
    scanf("%s %d",Q[i].name,&Q[i].n);
    enque(Q[i]);
  }
  while(1){
    if(head == tail) break;
    Qnow = deque();
    tt = mini(Qnow.n,time);
    Qnow.n -= tt;
    total += tt;
    if(Qnow.n == 0){
      Qt[count] = Qnow;
      Qt[count].n = total;
       count++;
    }
    else{
      enque(Qnow);
    }
  }
  for(i=0;i<n;i++){
    printf("%s %d\n",Qt[i].name,Qt[i].n);
  }
  
  return 0;
}