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

struct pp{
	char name[10];
	int time;
};

int head=0, tail=0;
struct pp que[100000];


void enqueue(struct pp *x){
	tail++;
	que[tail] = *x;
}


struct pp dequeue(){
	head++;
	return que[head];
}


int main(){
	int n, q, cnt=0, i, flag=0;
	struct pp temp;

	scanf("%d %d", &n, &q);
	tail = n;
	for(i=1; i<n+1; i++){
		scanf("%s %d", que[i].name, &que[i].time);
	}

	while(flag<n){
		temp = dequeue();
		if(temp.time>q){
			temp.time -= q;
			cnt += q;
			enqueue(&temp);
		}else{
			cnt += temp.time;
			printf("%s %d\n", temp.name, cnt);
			flag++;
		}
	}

	return 0;
}