#include<stdio.h>

struct QNode
{
	int t;
	char name[11];
};

typedef struct QNode Queue;

int rear, front, maxsize;

Queue Q[100001];

void enqueue(Queue q)
{
	front = (front + 1) % maxsize;
	Q[front] = q;
}

Queue dequeue()
{
	rear = (rear + 1) % maxsize;
	return Q[rear];
}

void solve()
{
	rear = front = 0;
	maxsize = 100001;

	int n, t, sum = 0;
	scanf("%d%d", &n, &t);

	for (int i = 0; i < n; i++)
	{
		front++;
		scanf("%s %d", Q[front].name, &Q[front].t);
	}

	while (rear != front)
	{
		Queue tmp;
		tmp = dequeue();
		if (tmp.t > t)
		{
			sum += t;
			tmp.t -= t;
			enqueue(tmp);
		}
		else
		{
			sum += tmp.t;
			printf("%s %d\n", tmp.name, sum);
		}
	}
		
}

int main()
{
	solve();
}
