#include<stdio.h>
#define MAXSIZE 200000
typedef struct data{
	char name[10];
	int time;
}Process;

Process Queue[MAXSIZE];
int bp=0,fp=0;

void push(Process p){
	Queue[bp]=p;
	bp++;
	if(bp == MAXSIZE)bp=0;
}
Process pop(){
	Process p = Queue[fp];
	fp++;
	if(fp == MAXSIZE)fp=0;
	return p;
}


int main(){
	int i,n,q,times;
	Process p;
	scanf("%d %d",&n,&q);
	
	for(i=0;i<n;i++){
		scanf("%s %d",&p.name,&p.time);
		push(p);
	}
	times = 0;
	while(1){
		p = pop();
		times += q;
		p.time -=  q;
		if(p.time<=0){
			printf("%s %d\n",p.name,(times+p.time));
			times += p.time;
		}
		else push(p);
		if(bp == fp)break;
	}
	
	
	return 0;
}