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


typedef struct{
  int time;
  char name[10];
}Pro;

int head,tail,n;
int  min(int,int);
void enqueue(Pro);
Pro dequeue(void);

Pro Q[N];

int main(){
  int q,i,c,e=0;
  Pro z;

  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s%d" ,Q[i].name,&Q[i].time);
  }
  head = 1;
  tail = n+1;
  while(head!=tail){
    z = dequeue();
    c = min(q,z.time);
    z.time -= c;
    e += c;
    if(z.time > 0){
      enqueue(z);
    }
    else printf("%s %d\n",z.name,e);
  }
  return 0;
}

void enqueue(Pro x){
  Q[tail] = x;
    tail = (tail + 1)% N;
   

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

int min(int v, int w){
  return v < w ? v:w;
}