#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#define MAX 100001

int n, head = 0, tail = 0;

typedef struct pp{
	char name[11];
	int time;
}P;

P Q[MAX + 1];

bool isEmpty(){
	return head == tail;	
}

bool isFull(){
	return head == (tail +1) % MAX;
}

void enqueue(P x){
	if (isFull())
		printf("overflow");
	Q[tail] = x;
	if ((tail+1)==MAX)
		tail = 0;
	else
		tail++;
}

P dequeue(/*int q[]*/){
	P x;
	if (isEmpty())
		printf("underflow");
	x = Q[head];
	if ((head+1) == MAX)
		head = 0;
	else
		head++;
	return x;
}

int main(void) {
	int q, i, total=0;
	P rr;
	
	scanf("%d %d", &n, &q);
	
	for (i = 1; i<=n; i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].time);
		enqueue(Q[i]);
	}
	do{
		if(Q[head].time<=q){
			total += Q[head].time;
			rr = dequeue();
			rr.time = total;
			printf("%s %d\n", rr.name, rr.time);
		}
		else{
			total += q;
			Q[head].time -= q;
			rr = Q[head];
			dequeue();
			enqueue(rr);

		}
	} while (!isEmpty());

	

	return 0;
}

