#include<stdio.h>
#define MAX 100005

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

P Q[MAX+1];//構造体増産

int head, tail, n;


void enqueue(P x) {
	
	Q[tail]=x;
	tail++;
	if(MAX<tail){
		tail=0;
	}
	
}

P dequeue() {
	
	P x=Q[head];
	head++;
	if(MAX<head){
		head=0;
	}
	return x;
}


int main() {
	int elaps = 0, c;
	int i, q;
	P a;
head = 1;
  tail = 1;
	
	scanf("%d %d", &n, &q);

	for ( i = 1; i <= n; i++) {
		scanf("%s %d", Q[i].name, &Q[i].t);
		
		enqueue(Q[i]);
	}
	
	
	while(head!=tail){
		
		a=dequeue();
		
		if(a.t<=q){
			elaps+=a.t;
			printf("%s %d\n", a.name, elaps);
			//count++;
		}
		else{
			elaps+=q;
			a.t-=q;
			enqueue(a);
		}
	}	
	return 0;
}
	
