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

typedef struct{
  char name[10];
  int  t;
} Process;

Process Q[100001];


int n,q,head,tail;


Process dequeue(){
  Process x;
  x=Q[head];
  if((head+1)>n+1) head=1;
  else            head++;
  return x;
}

void enqueue(Process x){
  Q[tail]=x;
  if((tail+1)==n+2)  tail=1;
  else             tail++;
}

int calc(int x,int y){
  if(x>=y) return y;
  else     return x;
}

int main() {
  /* code */
  Process hoz;
  int min_time=0;
  int sum_time=0;
  int i;

  scanf("%d %d\n",&n,&q);

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

  head=1;
  tail=n+1;

  //  printf("%s %d\n",Q[head].name,Q[head].t);
  

  while(head!=tail){
    hoz=dequeue();
    min_time=calc(q,hoz.t);
    hoz.t-=min_time;
    sum_time+=min_time;

    if(hoz.t>0){
      enqueue(hoz);
    }else{
      printf("%s %d\n",hoz.name,sum_time);
    }
  }
  return 0;
}