#include<stdio.h>
int main(void){
	int n,q,i;
	scanf("%d",&n);   scanf("%d",&q);
	char qname[n][11];
	int qtime[n];
	int next[n];
	int start=0,end=n-1;
	int cnt=0;
	scanf("%s",qname[0]);   scanf("%d",&qtime[0]);
	for(i=1;i<n;i++){
	scanf("%s",qname[i]);   scanf("%d",&qtime[i]);
	next[i-1]=i;
	}
	next[n-1]=-1;
	while(start!=-1){
		if(qtime[start]>q){
			qtime[start]-=q;
			next[end]=start;
			end=start;
			start=next[start];
			next[end]=-1;
			cnt+=q;
		}else{
			cnt+=qtime[start];
			printf("%s %d\n",qname[start],cnt);
			start=next[start];
		}
	}
	return 0;
}
