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

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

void enqueue(Que x);
Que dequeue();

Que Q[LEN];
int head, tail, n;

void enqueue(Que x)
{
	Q[tail] = x;
	tail = (tail +1) % LEN;

}

Que dequeue()
{
	Que x = Q[head];
	head = (head + 1)% LEN;
	return x;

}


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



