#include <stdio.h>
#include <string.h>
#define LEM 100005
typedef struct qq{
  char name[100];
  int t;
}Q;

Q QQ[LEM];

int head,tail,n,x;

void enqueue(Q);
Q dequeue(void);
int min(int,int);

int main(){

  int elaps=0,c;
  int i,q;
  Q u;
  scanf("%d %d",&n,&q);

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

   u=dequeue();
   c=min(q,u.t);
   u.t-=c;
   elaps+=c;
   if(u.t>0) enqueue(u);

   else{
     printf("%s %d\n",u.name,elaps);
   }
     }
  return 0;

}



void enqueue(Q x){


  QQ[tail]=x;
  tail = (tail+1)%LEM;
}

Q dequeue(){
  Q x;
  x=QQ[head];
  head =(head+1)%LEM;
  return x;

}

 int min(int x1,int x2){

   return x1 < x2 ? x1:x2;
  
 }

