#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include<math.h>
#define scani(x) scanf("%d",&x)
#define scanc(x) scanf("%s",x)
#define printi(x) printf("%d",x)
#define printin(x) printf("%d\n",x)
#define printc(x) printf("%s",x)
#define repd(i,n,m) for(int i = n; i > m; i--)
#define repu(i,n,m) for(int i = 0; i < m; i++)
#define allprintu(i,n,m,a) for(int i = 0; i < m; i++){if(i != m-1){printf("%d ",a[i]);}else{printf("%d\n",a[i]);}}
#define allprintd(i,n,m,a) for(int i = n; i > m; i--){if(i != 0){printf("%d ",a[i]);}else{printf("%d\n",a[i]);}}
#define LEN 100000

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

P Q[LEN];
int head,tail,n,q;


void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1)% LEN;
}
P dequeue(){
	P x = Q[head];
	head = (head + 1)%LEN;
	return x;
}

int min(int a, int b){
	return a < b ? a : b;
}


int main(void){
	P u;
	int elap = 0;

	scani(n);
	scani(q);

	repu(i,0,n){
		scanc(Q[i].name);
		scani(Q[i].t);
	}
	head = 0;
	tail = n;

	while(head != tail){
		u = dequeue();
		if(u.t <= q){
			printc(u.name);
			printf(" ");
			printin(u.t+elap);
			elap += u.t;
		}else{
			u.t -= q;
			enqueue(u);
			elap += q;
		}
		
	}
	return 0;
}
