#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pro{
	char name[100];
	int time;
}pro_in;

pro_in pros[LEN];
int head,tail,n;

void enqueue(pro_in x)
{
	pros[tail]=x;
	tail=(tail+1)%LEN;
}

pro_in dequeue()
{
	pro_in x;
	
	x=pros[head];
	head=(head+1)%LEN;
	
	return x;
}

int samll(int q,int t)
{
	if(t<q)
	{
		return t;
	}
	if(q<t)
	{
		return q;
	}
	if(q==t)
	{
		return t;
	}
}

int main(void)
{
	int i;
	int q;
	pro_in outp;
	int c,total=0;
	
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++)
	{
		scanf("%s",pros[i].name);
		scanf("%d",&pros[i].time);
	}
	
	head=1;
	tail=n+1;
	
	while(head!=tail)
	{
		outp=dequeue();
		c=samll(q,outp.time);
		outp.time-=c;
		total+=c;
		
		if(outp.time>0)
		{
			enqueue(outp);
		}
		else
		{
			printf("%s %d\n",outp.name,total);
		}
	}
	
	return 0;
}
