#include<stdio.h>
#include<string.h>
#define N 100000
#define QON 1000
#define LEN 100005

int min(int a, int b){
 
  return a < b ? a:b;

}

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

Process Q[LEN+1];
int head=1, tail=0, n;

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

  if( tail != LEN )
    tail++;
  else
    tail=1;
}

Process dequeue(){

  Process x;
  x=Q[head];

  if( head != LEN )
    head++;
  else 
    head=1;
  
return x;
}


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

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

  tail=n+1;

  while( head != tail ){
    
    u = dequeue();
    c = min(q,u.time);
    u.time = c;
    elaps += c;
    
    if( u.time <= 0)
      printf("%s %d\n",u.name,elaps);
    else if(u.time>0)
      enqueue(u);
  }
  
  return 0;
}