#include <stdio.h>
typedef struct
{
	char name[10];
	int time;	
}queue; 

queue a[100001];
int head,tail,n,q;

void enqueue(queue u)
{
	a[tail]=u;
	tail=(tail+1)%(n+1);	
}

queue dequeue()
{
	queue copy=a[head];
	head=(head+1)%(n+1);
	return copy;		
}

int main(int argc, char *argv[])
{
	int i,totaltime=0;
	queue u;
	scanf("%d%d",&n,&q);
	for(i=0;i<n;i++)
	scanf("%s%d",a[i].name,&a[i].time);
	head=0,tail=n;
	while(head!=tail)
	{
		u=dequeue();
		if(u.time<=q)
		{
			totaltime=totaltime+u.time;
			printf("%s %d\n",u.name,totaltime);		
		}
		else
		{
			totaltime=totaltime+q;
			u.time=u.time-q;
			enqueue(u);
		}
	}
	return 0;
}