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

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

Work a[N];
Work *head;
int head_id;
Work *tail;
int tail_id;
	

void dequeue(int n){

	for(int i=head_id+1;i<n+head_id;i++){
		if(a[i%n].t!=0){
			head_id=i%n;
			head=&a[i%n];
			return;
		}
	}
	return;
}

void enqueue(int n){
	
	for(int i=tail_id+1;i<n+tail_id;i++){
		if(a[i%n].t!=0){
			tail_id=i%n;
			tail=&a[i%n];
			return;
		}
	}
	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=&a[0];  tail=&a[n-1];
	head_id=0;  tail_id=n-1;
	
	while(sum_t<sum){
		
		if(head->t == q){
			sum_t+=q;
			head->t=0;
			printf("%s %d\n",head->name,sum_t);
			dequeue(n);
		}
		
		else if(head->t < q){
			sum_t+=head->t;
			head->t=0;
			printf("%s %d\n",head->name,sum_t);
			dequeue(n);
		}
		
		else {
			sum_t+=q;
			head->t-=q;
			dequeue(n);
			enqueue(n);
		}
		
	}
	
	return 0;
	
}
