#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
struct duilie {
    char name[10];
    int time;
} Q[MAX];

int head;
int tail;
int max;

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

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

int isFull(){
    return (head == tail+1) || (tail+1 == MAX && head == 0);
    //return head == (tail+1)%MAX
}

void enqueue(struct duilie x){
    if (isFull()){
        printf("Full, error\n");
        exit(-1);
    }
    Q[tail] = x;
    if (tail+1 == MAX)
        tail = 0;
    else
        tail++;
}

struct duilie dequeue(){
    if (isEmpty()){
        printf("Empty, error\n");
        exit(-1);
    }
    struct duilie tmp = Q[head];
    if (head+1 == MAX)
        head = 0;
    else
        head++;    

    return tmp;
}

int main (){
    initialize();
    int n, split;
    scanf("%d", &max);
    scanf("%d", &split);
    for (int i = 0; i < max; i++){
        scanf("%s", &Q[i].name);
        scanf("%d", &Q[i].time);
		tail++;
    }
    int totalTime = 0;
	while (!isEmpty()){
		if (Q[head].time <= split){
			totalTime += Q[head].time;
			printf("%s %d\n", Q[head].name, totalTime);
			dequeue();
		}
		else {
			totalTime += split;
            Q[head].time -= split;
			enqueue(dequeue());
		}
	}
    return 0;
}
