#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define SIZE 100001

typedef struct {
	char name[10];
	int time;
} process;

typedef struct {
	int head,tail,count,size;
	process *data;
} Queue;

process nullp = {"", 0};

bool isFull(Queue *que);
bool enqueue(Queue *que, process p);
bool isEmpty(Queue *que);
process dequeue(Queue *que, int *err);



int main(){

	int n, q, time=0, i;
	int err;
	process p;

	scanf("%d %d",&n,&q);
	Queue *que = malloc(sizeof(Queue));
  	if (que != NULL) {
    	que->head = 0;
    	que->tail = 0;
    	que->count = 0;
    	que->size = n;
    	que->data = malloc(sizeof(process) * que->size);
    }
    for(i=0; i<n; i++){
    	scanf("%s %d",&p.name, &p.time);
    	enqueue(que, p);
    }

    while(!isEmpty(que)){
    	p = dequeue(que, &err);
    	if(p.time > q){
    		time += q;
    		p.time -=q;
    		enqueue(que, p);
    	}else{
    		time += p.time;
    		printf("%s %d\n",p.name,time);
    	}
    }


	return 0;
}

bool isFull(Queue *que){
  return que->count == que->size;
}

bool enqueue(Queue *que, process p){
  if (isFull(que)) return false;
  que->data[que->tail++] = p;
  que->count++;
  if (que->tail == que->size)
    que->tail = 0;
  return true;
}

bool isEmpty(Queue *que){
  return que->count == 0;
}

process dequeue(Queue *que, int *err){
  if (isEmpty(que)) {
    *err = 0;
    return nullp;
  }
  process p = que->data[que->head++];
  que->count--;
  *err = 1;
  if (que->head == que->size)
    que->head = 0;
  return p;
}