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

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

process Q[N];
int head;
int tail;

void initialize(){
	head = tail = 0;
}

int isEmpty(){
	return head == tail;
}

int isFull(){
	return head == (tail + 1)%N;
}

void enqueue(char *name,int tim){
	if(isFull()){
		printf("error\n");
	}else{
		strcpy(Q[tail].name,name);
		Q[tail].time = tim;
		if(tail+1==N)tail=0;
		else tail++;
	}
}

int dequeue(){
	if(isEmpty()){
		printf("error\n");
	}else{
		int tmp = head;
		if(head+1==N)head=0;
		else head++;
		return tmp;
	}
}

int main()
{
	int q;
	int n;
	int t;
	int ti=0;
	char c[100];
	int i;
	scanf("%d %d",&n,&q);
	initialize();
	for(i=0;i<n;i++){
		scanf("%s %d",c,&t);
		enqueue(c,t);
	}
	while(!isEmpty()){
		int t = dequeue();
		Q[t].time -= q;
		ti += q;
		if(Q[t].time<=0){
			ti += Q[t].time;
			printf("%s %d\n",Q[t].name,ti);
		}else{
			enqueue(Q[t].name,Q[t].time);
		}
	}

	return 0;
}