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

#define LEN 100005
typedef struct pp{
	char name[100];
	int time;
}P;

P Q[LEN+1];
int main(void){

	int n, q;
	int j, top;
	P change;
	int i, cnt, t;
	cnt =0;
	scanf("%d %d", &n, &q);
	t =0;
	for(i =0;i<n;i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].time);	
		
	}
	
	top=0;
	i=0;
	j=0;
	while(cnt !=n ){
		if(i ==n-cnt+top){
			i =0;
			top=0;
			j=0;
		}
		if(Q[i].time <=q && Q[i].time != 0 ){
			
			t =t + Q[i].time;
			Q[i].time = 0;
			cnt++;
			top++;
			printf("%s %d\n", Q[i].name, t);
			
		}
		else if(Q[i].time != 0 ){
			Q[i].time = Q[i].time - q;
			t = t+ q;
			
			
			Q[j] =Q[i];
			j++;
		}
		i++;
		
		
		
		/*
		change = Q[0];
		for(i = 0;i<n-1;i++){
			Q[i] = Q[i+1];
		}
		Q[n-1] = change;
		*/	
		
	}
	
	
	return 0;
}
