#include <stdio.h>

typedef struct{
	char name[10];
	int t;
}Process;

int main(){
	int n,q;
	Process Q[100000];
	int EndProcess = 1;
	int EndTime = 0;
	
	Process key;
	
	int i,j;
	
	//Input Process
	scanf("%d %d",&n,&q);
	
	for(i = 0;i < n;i++){
		scanf("%s%d",&Q[i].name,&Q[i].t);
	}
	
	//Do Process
	while(EndProcess <= n){
		for(i = 0;i < n;i++){
			if(Q[i].t != 0){
				if(Q[i].t - q <= 0){
					EndTime += Q[i].t;
					
					Q[i].t = 0;
					
					printf("%s %d\n",Q[i].name,EndTime);
					EndProcess++;
				}else{
					Q[i].t -= q;
					EndTime += q;
				}
			}
		}
	}
	
	return 0;
}