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

#define N 1000000

struct queue {
	int data[N];
	char name[N][11];
	int head;
	int tail;
	int max;
};

void initialize( struct queue *q, int max ) {
	int i = 0;
	int j = 0;
	
	q -> head = 0;
	q -> tail = 0;
	q -> max = max;
	for( i = 0; i < max; i++ ) {
		q -> data[i] = 0;
		for ( j = 0; j < 11; j++ ) {
			q -> name[i][j] = '\0';
		}
	}
}

void enqueue( struct queue *q, int item, char* name ) {
	int i = 0;
	
	if ( q -> tail >= q -> max ) {
		q -> tail = 0;
	}
	
	q -> data [ q -> tail ] = item;
	for ( i = 0; name[i] != '\0'; i++ ) {
		q -> name [ q -> tail ][i] = name[i];
	}
	q -> name[ q -> tail ][i] = '\0';
	q -> tail++;
	
}

int dequeue( struct queue *q , char* name ) {
	int tmp = 0;
	int i = 0;
	
	if ( q -> head >= q -> max ) {
		q -> head = 0;
	}
	

		tmp = q -> data[ q -> head ];
		for ( i = 0; q -> name [ q -> head ][i] != '\0'; i++ ) {
			name[i] = q -> name [ q -> head ][i];
		}
		name[i] = '\0';
		q -> head++;
		return tmp;
}

int main(void)
{
	int max_order			= 0;
	int quantum				= 0;
	char str[256]			= {};
	int i 					= 0;
	int j					= 0;
	struct queue process	= {};
	int total_time			= 0;
	int flag				= 0;
	int time				= 0;
	int result[N]			= {};
	char result_name[N][11] = {};
	
	fgets( str, 256, stdin );
	for ( i = 0; str[i] != ' '; i++ ) {
	}
	str[i] = '\0';
	max_order = atoi(&str[0]);
	quantum   = atoi(&str[i+1]);
	
	initialize( &process, max_order );
	
	
	for ( j = 0; j < max_order; j++ ) {
		fgets( str, 256, stdin );
		for ( i = 0; str[i] != ' '; i++ ) {
		}
		str[i] = '\0';
		enqueue( &process, atoi(&str[i+1]), &str[0] );
	}
//	enqueue( &process, atoi(&str[i+1]), &str[0] );

	j = 0;
	flag = 0;
	total_time = 0;
	time = 0;
	
	
	while ( 1 ) {
		if ( flag >= max_order ) {
			break;
		}
		
		time = dequeue( &process, str );

		if ( time <= quantum ) {
			total_time += time;
			result[j] = total_time;
			for ( i = 0; str[i] != '\0'; i++ ) {
				result_name[j][i] = str[i];
			}
			result_name[j][i] = '\0';
			j++;
			flag++;
			
		} else {
			time -= quantum;
			total_time += quantum;
			enqueue(&process, time, str);
		}
	}
	
	for ( i = 0; i < max_order; i++ ) {
		printf("%s %d\n", result_name[i], result[i]);
	}
		
	
	
	
	return 0;
}
