#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int pop();
int main(){
  int i,now=0,n,remain,q,time[100000];
  char name[100000][10];
  scanf("%d %d",&n,&q);
  remain =n;
  for(i=0;i<n;i++) scanf("%s %d",name[i],&time[i]);
    i=0;
  while(remain!=0){
	if(now==n) now=0;
    if(time[now]<=0){
      while(time[now]<=0) {
	now++;
	if(now==n) now=0;
      }
      
    }
    if(time[now] -q <= 0){
      printf("%s %d\n",name[now],i + time[now]);
      i+=time[now];
      remain--;
      time[now]-=q;
      continue;
    }
    time[now]-=q;
    i+=q;
    now++;
  }
}
