#include <stdio.h>
#include <string.h>
int main(){
	int n,q;
	scanf("%d %d",&n,&q);
	int i;
	char name[n][10];
	int time[n+1];
	for(i=0;i<n;i++){
		scanf(" %s %d",name[i],&time[i]);
	}
	time[n]=0;
	int now=0;
	int temp;
	char move[10];
	while(time[0]!=0){
		if(time[0]>q){
			i=1;
			temp=time[0]-q;
			strcpy(move,name[0]);
			while(time[i]!=0){
				time[i-1]=time[i];
				strcpy(name[i-1],name[i]);
				i++;
			}
			i--;
			time[i]=temp;
			strcpy(name[i],move);
			now+=q;
		}
		else{
			now+=time[0];
			printf("%s %d\n",name[0],now);
			i=1;
			while(time[i]!=0){
				time[i-1]=time[i];
				strcpy(name[i-1],name[i]);
				i++;
			}
			i--;
			time[i]=0;
			name[i][0]='\0';
		}
	}
	return 0;
}