/* ALDS1_3_B_Queue */

#define _CRT_SECURE_NO_WARNINGS

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

#define N 100000
#define NM 10

typedef struct {
	char name[NM];
	int time;
} Queue;

int tail, head, sum_t;
Queue que[N];

void enqueue(Queue m);
Queue dequeue(void);
void initialize();

int main(void){
	int n, q, i;
	Queue temp;
	Queue *A = (Queue *)malloc(sizeof(Queue) * N);

	initialize();
	sum_t = 0;
	scanf("%d%d", &n, &q);
	for(i = 0; i < n; i++){
		scanf("%s%d", A[i].name, &A[i].time);
		enqueue(A[i]);
	}

	while(head != tail){
		temp = dequeue();
		if(temp.time <= q){
			sum_t += temp.time;
			printf("%s %d\n", temp.name, sum_t);
		}else{
			temp.time -= q;
			sum_t += q;
			enqueue(temp);
		}
	}

	return 0;
}

void initialize(){
	head = tail = 0;
}

void enqueue(Queue m){
	que[tail] = m;
	tail = (tail + 1) % N;
}

Queue dequeue(){
	Queue ret = que[head];

	head = (head + 1) % N;

	return ret;
}


