#include<stdio.h>
#include<string.h>
#define N 100000

typedef struct work{
	char name[12];
	int t;
}Work;

Work a[N+1];
int head;
int tail;
	

void dequeue(int n){

	head=(head+1)%(n+1);
	
	return;
}

void enqueue(Work x,int n){
	
	tail=(tail+1)%(n+1);
	a[tail]=x;
	
	return;
}

int main(){
	int n,q,i;
	int sum_t=0;
	int sum=0;
	char temp[12];
	
	scanf("%d %d",&n,&q);
	
	for(i=0;i<n;i++){
		scanf("%s %d",temp,&a[i].t);
		strcpy(a[i].name,temp);
		sum+=a[i].t;
	}
	
	head=0;	tail=n-1;
	
	while(sum_t<sum){
		
		if(a[head].t == q){
			sum_t+=q;
			a[head].t=0;
			printf("%s %d\n",a[head].name,sum_t);
			dequeue(n);
		}
		
		else if(a[head].t < q){
			sum_t+=a[head].t;
			a[head].t=0;
			printf("%s %d\n",a[head].name,sum_t);
			dequeue(n);
		}
		
		else {
			sum_t+=q;
			a[head].t-=q;
			enqueue(a[head],n);
			dequeue(n);
		}
		
	}
	
	return 0;
	
}
