#include <stdio.h>

#define MAX 100000

typedef struct _process {
	int q;
	char name[11];
} process_t;

int main()
{
	process_t pr[MAX];
	int num, qt, i, max;
	int spent = 0;

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

	for ( i = 0 ; i < num ; i++ ) {
		scanf( "%s %d", pr[i].name, &pr[i].q );
	}

	i = 0;
	max = num;;
	while ( num > 0 ) {
		if ( pr[i%max].q > 0 ) {
			if ( pr[i%max].q - qt <= 0 ) {
				spent += pr[i%max].q;
				pr[i%max].q -= qt;
				printf( "%s %d\n", pr[i%max].name, spent );
				num--;
			} else {
				pr[i%max].q -= qt;
				spent += qt;
			}
		}
		i++;
	}

	return 0;
}

