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

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

P Q[LEN];
int head, tail;

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)
{
	if(a <= b) return a;
	else return b;
}

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