#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000
int head,tail;
int Q[MAX];
char QN[MAX][11];
char retname[11];

void initialize(void){
	head=0;
	tail=0;
}

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

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

void enqueue(char *name, int x){
	if(isFull()){
		exit(1);
	}
	strcpy(QN[tail],name);
	Q[tail]=x;
	if(tail+1==MAX){
		tail=0;
	}else{
		tail++;
	}
}

int dequeue(){
	int x;
	if(isEmpty()){
		exit(1);
	}
	x=Q[head];
	strcpy(retname,QN[head]);
	if(head+1==MAX){
		head=0;
	}else{
		head++;
	}
	return x;
}

int main(void){
	int n,q;
	int alltime=0;
	int i;
	char inputN[11];
	int inputT;
	scanf("%d",&n);
	scanf("%d",&q);
	initialize();
	for(i=0;i<n;i++){
		scanf("%s",inputN);
		scanf("%d",&inputT);
		enqueue(inputN, inputT);
	}
	int useT;
	while(1){
		if(isEmpty()==1) break;
		useT=dequeue();
		if(useT<=q){
			alltime+=useT;
			printf("%s %d\n",retname,alltime);
		}else{
			alltime+=q;
			useT-=q;
			enqueue(retname,useT);
		}
	}
	
	return 0;
}