#include<stdio.h>

int head,tail,MAX;
typedef struct{
	char name[10];
	int times;
} queue;
queue Q[100002],stack;

int Empty()
{
	if(head==tail){return 1;}
	else{return 0;}
}
int Full()
{
	if(head==(tail+1)%MAX){return 1;}
	else{return 0;}
}
int append(queue *Q,queue x)
{
	if(Full()){printf("error. overflow.");return -1;}
	Q[tail]=x;
	if(tail+1==MAX){tail=0;}
	else{tail++;}
	return 0;
}
queue recall(queue *Q,queue x)
{
	if(Empty()){printf("error. underflow.");return x;}
	x=Q[head];
	if(head+1==MAX){head=0;}
	else{head++;}
	return x;
}
int main(void)
{
	int i,n,q,T=0;
	scanf("%d %d",&n,&q);
	head=tail=0;MAX=n+1;
	for(i=0;i<n;i++)
	{
		scanf("%s %d",stack.name,&stack.times);
		append(Q,stack);
	}
	while(!Empty())
	{
		stack=recall(Q,stack);
		if(stack.times>q){
			stack.times-=q;
			T+=q;
			append(Q,stack);
		}else{
			T+=stack.times;
			printf("%s %d\n",stack.name,T);
		}
	}

	return 0;
}