#include<stdio.h>

#define MAX 100001 

typedef struct tq{
	char name[10];
	int time;
} s;

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

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

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

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