#include<stdio.h>
#include<stdlib.h>
#define len 100005
typedef struct pp{
	char name[100];
	int t;
}p;
p q[len];
int head,tail,n;

void enqueue(p x){
q[tail]=x;
tail=(tail+1)%len;
} 
p dequeue(){
	p x=q[head];
	head=(head+1)%len;
	return x;
}
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	int elaps=0,c;
	int i,e;
	p u;
	scanf("%d %d",&n,&e);
	for(i=1;i<=n;i++)
	{
		scanf("%s",q[i].name);
		scanf("%d",&q[i].t);
	}
	head=1;tail=n+1;
	while(head!=tail){
		u=dequeue();
		c=min(e,u.t);
		u.t-=c;
		elaps+=c;
		if(u.t>0) enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}		
	}
	return 0;
}
