#include <stdio.h>
#include <stdbool.h>
#define MAX_P 100000

int i=0,head,tail,TIME=0;
int MAX,QUAM;

struct que{
	char N[20];
	int Ptime;
};
struct que Q[MAX_P];

int main(){
    scanf("%d%d",&MAX,&QUAM);
    for(tail=0;tail<MAX;tail++){
        scanf("%s %d",&Q[tail].N,&Q[tail].Ptime);
    }

	for(head=0,tail=MAX;head!=tail;head=(head+1)%(MAX+1))
	{
		i=head;
		if(Q[i].Ptime<=QUAM)
		{
			TIME+=Q[i].Ptime;
			printf("%s %d\n",Q[i].N,TIME);
			Q[i].Ptime=0;
		}else    		{
			TIME+=QUAM;
			Q[tail].Ptime=Q[i].Ptime-QUAM;
			strcpy(Q[tail].N,Q[i].N);
			tail=(tail+1)%(MAX+1);
		}
	}
	return 0;
}
