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

#define MAX 100000

typedef struct{
	char name[100];
	int t;
}Elements;

Elements Q[MAX];
int head=0;
int tail=0;
int n;

void enqueue(Elements x){
	Q[tail]=x;
	if(tail==n-1) tail=0;
	else tail++;
}

Elements dequeue(){
	Elements x;
	x=Q[head];
	if(head==n-1) head=0;
	else head++;
	return x;
}

int main(){
	int i,q,count=0,tim=0;
	Elements p;

	scanf("%d %d",&n,&q);
	for(i=0;i<n;i++){
		scanf("%s %d",Q[i].name,&Q[i].t);
	}

	while(count<n){
		p=dequeue();
		if(p.t<=q){
			tim+=p.t;
			printf("%s %d\n",p.name,tim);
			count++;
		}else{
			tim+=q;
			p.t-=q;
			enqueue(p);
		}
	}
	return 0;
}