#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXn 1000000
#define MAXMO 10

typedef struct {
  char Name[MAXMO];
  int time;
}Process;

Process A[MAXn];

int main(){
  int i,n,q,o=0,j,count=0;
  Process k;

  scanf("%d %d",&n,&q);

  for( i=0 ; i<n ; i++ ){
    scanf("%s %d",A[i].Name,&A[i].time);
  }
  
  while(1){
    if(n == 0)break;
    if(A[0].time > q){
      A[0].time = A[0].time - q;
      o = o+q;
      for( j=0 ; j<n-1 ; j++ ){
	k = A[j];
	A[j] = A[j+1];
	A[j+1] = k;
      }
    }
    else if(A[0].time <= q && A[0].time > 0){
      o = o + A[0].time;
      A[0].time = 0;
      printf(" %s %d\n",A[0].Name,o);
      n--;
      count++;
      for( j=0 ; j<n ; j++ )
	A[j] = A[j+1];
      
    }
  }
  return 0;
}

