#include<stdio.h>
#define MAX 100000
typedef struct{
	char name[100];
	int time;
} roll;

void enqueue(roll);
roll dequeue(void);

int head=0,tail=0;
roll Q[MAX];

	int main(void){
	int n,q,i,sum=0;
	roll p;

		scanf("%d%d",&n,&q);
		for(i=0;i<n;i++){
			scanf("%s%d",p.name,&p.time);
			enqueue(p);
		}
		while(1){
			if(head == tail) break;
			if(Q[head].time > q){
				p = dequeue();
				p.time -= q;
				enqueue(p);
				sum += q; 
			}
			else{
				p = dequeue();
				printf("%s %d\n",p.name,p.time+sum);
				sum += p.time;
			}
		}
return 0;
}

void enqueue(roll p){
Q[tail] = p;
if(tail+1 == MAX) tail = 0;
else tail++;
}

roll dequeue(){
	roll x;
	x = Q[head];

	if(head+1 == MAX) head = 0;
	else head++;
	return x;
}