#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 100000

typedef struct cpu
{
	char name[10];
	int time;
} cpu_t;

cpu_t queue[MAX];
int number = 0;

void enq( cpu_t info )
{
	strcpy( queue[number].name, info.name );
	queue[number].time = info.time;
	number = number + 1;
}

cpu_t deq( )
{
	int i = 0;
	cpu_t tmp;

	strcpy( tmp.name, queue[0].name );
	tmp.time = queue[0].time;

	for ( i = 1; i < number ; i++ )
	{
		strcpy( queue[i - 1].name, queue[i].name);
		queue[i - 1].time = queue[i].time;
	}
	number = number - 1;
	return tmp;
}

int main()
{
	int num, i, q, time_com = 0;
	cpu_t cpuinfo;

	scanf( "%d %d", &num, &q );

	for ( i = 0 ; i < num ; i++ )
	{
		scanf( "%s", &cpuinfo.name );
		scanf( "%d", &cpuinfo.time );
		enq( cpuinfo );
	}

	while ( number > 0 )
	{
		cpuinfo = deq();
		if ( cpuinfo.time <= q )
		{
			time_com = time_com + cpuinfo.time;
			fprintf( stdout, "%s %d\n", cpuinfo.name, time_com );
		}
		else
		{
			time_com = time_com + q;
			cpuinfo.time = cpuinfo.time - q;
			enq( cpuinfo );
		}
	}

	return 0;
}