#include <stdio.h>
#include <string.h>
typedef struct{
  char name[10];
  int time;
}Process;
void enqueue(Process);
Process dequeue(void);
int n;
int head = 0;
int tail = 0;
Process p[100001];
int main(){
  int i,q,takenTime;
  Process x;

  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",x.name,&x.time);
    enqueue(x);
  }
  takenTime = 0;
  while( head != tail ){
    x = dequeue();
    if( (x.time - q) > 0 ){
      takenTime += q;
      enqueue(x);
    }
    else {
      takenTime += x.time;
      printf("%s %d\n",x.name,x.time);
    }
  }
  return 0;
}
void enqueue(Process x){
  p[tail] = x;
  if( (tail+1) > n){
    tail = 0;
  }
  else {
    tail++;
  }
}
Process denqueue(void){
  if( (head+1) > n ){
    head = 0;
  }
  else {
    head++;
  }
  return p[head];
}