#include<stdio.h>
#include<string.h>
#define M 100000

typedef struct{
  char name[100];
  int time;
}Que;

int head,tail,n;

int min(int,int);
Que dequeue(void);
void enqueue(Que);
Que Q[M];

 int main(){
  
  
  int e=0,d;
   int i,q;
   Que p;
   
   scanf("%d %d",&n,&q);
   
   for(i=1;i<=n;i++){
     scanf("%s",Q[i].name);
     scanf("%d",&Q[i].time);
   }

   head=1;
  tail=n+1;
   
   while(head!=tail){
     p=dequeue();
     d=min(q,p.time);
     p.time-=d;
     e+=d;
     if(p.time>0) enqueue(p);
     else {
       printf("%s %d\n",p.name,e);
     }
   }
   return 0;
}

int min(int x, int y){ 
  return x < y ? x : y;
}

Que dequeue(){
  Que x;
 x= Q[head];
  head = (head + 1) % M;
  
  return x;
}

void enqueue(Que x){ 
  
  Q[tail] = x;

  tail = (tail + 1) % M;
  
}