#include<stdio.h>

#define SIZE 100000
#define L 10

typedef struct{
	char name[L];
	int time;
}process;

process queue[SIZE];
int head=0;
int tail=0;

void enq(process n){
	queue[tail++]=n;
	tail%=SIZE;
}

process deq(){
	process n=queue[head++];
	head%=SIZE;
	return n;
}

int main(void){
	int n,q;
	int i;
	int t=0;
	process p;
	scanf("%d %d",&n,&q);
	
	for(i=0;i<n;i++){
		scanf("%s",p.name);
		scanf("%d",&p.time);
		enq(p);
	}
	
	while(n>0){
		p=deq();
		if(p.time<=q){
			t+=p.time;
			printf("%s %d\n",p.name,t);
			n--;
		}else{
			p.time-=q;
			enq(p);
			t+=q;
		}
	}
	
	return 0;
}