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

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

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