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

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

Process p[100000];
int head,tail;

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

int isFull(){
	return head == (tail + 1) % 100000;
}

void enqueue(Process x){
	if(isFull()){
		exit(1);
	}
	p[tail] = x;
	if(tail+1 == 100000){
		tail = 0;
	}else{
		tail++;
	}
}

Process dequeue(){
	Process x = p[head];
	if(head + 1 == 100000){
		head = 0;
	}else{
		head++;
	}
	return x;
}

int main(void){
	int n,i,q,sum = 0;
	Process x;
	scanf("%d %d",&n,&q);
	for(i=0;i<n;i++){
		scanf("%s %d",p[i].name,&p[i].time);
	}
	head = 0,tail = n;
	while(isEmpty() != 1){
		x = dequeue();
		if(x.time <= q){
			sum += x.time;
			printf("%s %d\n",x.name,sum);
		}else{
			sum += q;
			x.time -= q;
			enqueue(x);
		}
	}
	return 0;
}
