#include <stdio.h>


typedef struct{
char name[10];
int time;
}queue;

queue Q[100000];

int head=0;
int tail=0;


void enqueue(queue ,int);
queue dequeue(int);

int main(){
	int n,i,q;
	int count=0;
	scanf("%d%d",&n,&q);
	queue Que;

	for(i=0;i<n;i++){
		scanf("%s",Que.name);
		scanf("%d",&Que.time);
		enqueque(Que,n);
	}



	while(1){
		if(head==tail)break;
	
		if(Q[head].time<=q){
			Que=dequeue(n);
			count+=Que.time;
			printf("%s %d\n",Que.name,count);
		}
		else{
			Que=dequeue(n);
			Que.time-=q;
			count+=q;
			enqueue(Que,n);
		}
	}	

	return 0;
}

void enqueue(queue x,int n){
	Q[tail]=x;
	if(tail+1==n)tail=0;
	else tail++;
}



queue dequeue(int n){
	queue x;
	x=Q[head];
	if(head+1==n)head=0;
	else head++;
	return x;
}