#include <stdio.h>
#define N 200000
typedef struct process{
	char name[11];
	int time;
}process;

process P[N];
int head = 0;
int bottom = 0;

void push(process x){
	P[head%N]= x;
	head++;
}
process pop(void){
	int d;
	d = bottom%N;
	bottom++;
	return P[d];
}

int main(int argc, char argv[]){
	int n;
	int q;
	int t=0;
	scanf("%d %d",&n,&q);
	process ins;

	int i;
	for(i=0;i<n;i++){
		scanf("%s %d",ins.name,&ins.time);
		push(ins);
	}

	while(head!=bottom){
		ins = pop();
		if(ins.time-q>0){
			ins.time -= q;
			push(ins);
			t += q;
		}else{
			t += ins.time;
			printf("%s %d\n",ins.name,t);
		}
	}

	return 0;
}