#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(){
	int n,q;
	char **name;
	int *time;
	int count=0,now=0,point=0;
	
	scanf("%d %d",&n,&q);

	name=(char**)malloc(sizeof(char*)*n);
	time=(int*)malloc(sizeof(int)*n);
	for(int i=0;i<n;i++){
		name[i]=(char*)malloc(sizeof(char)*11);
		scanf("%s %d",name[i],&time[i]);
	}

	while(count!=n){
		if(time[point]<=q){
			now+=time[point];
			printf("%s %d\n",name[point],now);
			count++;
			time[point]=0;
		}else{
			time[point]-=q;
			now+=q;
		}
		if(count<n){
			while(1){
				if((point+1)==n){
					point=0;
				}else{
					point++;
				}
				if(time[point]!=0){
					break;
				}
			}
		}
	}


   return 0;
}
