#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, head = 0, tail = 0;

void enq( cpu_t info )
{
	if ( tail == number )
	{
		tail = 1;
	}
	else 
	{
		tail = tail + 1;
	}

	queue[tail] = info;
}

cpu_t deq( )
{
	if ( head == number )
	{
		head = 1;
	}
	else 
	{
		head = head + 1;
	}

	return queue[head];
}

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

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

	for ( i = 1 ; i < number+1 ; i++ )
	{
		scanf( "%s", queue[i].name );
		scanf( "%d", &queue[i].time );
	}

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

	return 0;
}