#include <stdio.h>
#include <stdlib.h>

int head=0;
int tail;
int Q[100000];


void initiaize(void);
int isEmpty(void);
int isFull(void);
int dequeue(int );
void enqueue(int ,int );

int main(){
	int n,q,i;
	int count=0,extend;
	scanf("%d%d",&n,&q);
	char name[n][10];
	tail=n;
	for(i=0;i<n;i++){
		scanf("%s",name[i]);
		scanf("%d",&Q[i]);
	}
	i=0;
	while(1){
		if(i==n)break;
		extend=dequeue(n);
		if(extend<=q){
			count+=extend;
			if(head==0)printf("%s %d\n",name[7],count);
			else printf("%s %d\n",name[head-1],count);
			i++;
		}
		else{
			count+=q;
			extend-=q;
			if(head==0)strcpy(name[tail],name[7]);
			else strcpy(name[tail],name[head-1]);
			enqueue(extend,n);
		}
	}	

	return 0;
}



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


int isEmpty(){
	if(head == tail)return 1;
	else return 0;
}

int isFull(){
	if(head == (tail+1)% 100000)return 1;
	else return 0;
}

void enqueue(int x,int n){
	if(isFull()==1)exit(0);
	Q[tail]=x;
	if(tail+1==n)tail=0;
	else tail++;
}



int dequeue(int n){
	int x;
	if(isEmpty==1)exit(1);
	x=Q[head];
	if(head+1==n)head=0;
	else head++;
	return x;
}