#include<stdio.h>
#define N 100000

typedef struct{
  char n[10];
  int q;
}Data;


int main(){
  int n,q,i,j,head=0,tail,sum=0;
  Data data[N];

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

  for(i=0;i<n;i++){
    scanf("%s%d",&data[i].n,&data[i].q);
  }

  head=0;
  tail=n;
  while(1){
    data[head].q-=q;
    sum+=q;
    if(data[head].q<=0){
      printf("%s %d\n",data[head].n,data[head].q+sum);
      sum=0-data[head].q;
    }
    else {
      data[tail]=data[head];
      tail++;
    }
    head++;
    if(head==tail)break;
  }
  return 0;
}