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

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


void enqueue(P);
P dequeue(void);

int n;
int head=0, tail=0;
P Q[N+1];

int main()
{
	int i,q;
	int st=0,cnt=0;
	P u;
	
	scanf("%d%d",&n,&q);
	
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].time);
	}
	
	head = 1;
	tail=n+1;
	while(cnt < n)
	{
		if(Q[head].time <= q)
		{
			st = st + Q[head].time;
			u = dequeue();
			printf("%s %d\n", u.name, st);
			cnt++;
		}
		else
		{
			st = st + q;
			Q[head].time = Q[head].time - q;
			u = dequeue();
			enqueue(u);
		}
	}
	return 0;
}

void enqueue(P x) {
	Q[tail] = x;
	if(tail + 1 == N){
		tail = 0;
	}
	else{
		tail++;
	}
}
 
P dequeue(void) {
	P x;
	x = Q[head];
	if(head + 1 == N)
	{
		head = 0;
	}
	else
	{
		head++;
	}
	return x;
}