#include <stdio.h>

typedef struct{
	char name[10];
	int t;
} process;
int n,q;
int i=0,j=0;
int timer=0;
int head=0;
int flag=0;
process x[1000];

int main(void){
	scanf("%d%d",&n, &q);
  for(i=0;i<n;i++){
  	scanf("%s%d",x[i].name,&x[i].t);
  	}
  i=0;
  while(flag!=n){
   if(x[i].t<=q && x[i].t!=-1){
   	timer+= x[i].t;
   	printf("%s %d\n",x[i].name,timer);
   	x[i].t = -1;
   	flag++;
   }
   if(x[i].t>q){
   	timer+= q;
   	x[i].t-=q;
   }
   i++;
   if(i==n){
   	i=0;
   }
  }
}