#include <stdio.h>
#include <string.h>
 
#define MAX 100005 

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

P Q[MAX];
int tail, head, n;

void enqueue(P x)
{
	Q[tail] = x;
	tail = (tail + 1) % MAX;
}

P dequeue()
{
	P x = Q[head];
	head = (head + 1) % MAX;
	return x;
}

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