#include<stdio.h>
struct Node{
	char name[12];
	int time;
	struct Node *last;
	struct Node *next;
};
int n,q;
struct Node *head = NULL;
struct Node *tail = NULL;
int globalTime;
int main(){
	scanf("%d %d",&n,&q);
	int i;
	struct Node *node;
	for(i=0;i<n;i++){
		node = (struct Node *)malloc(sizeof(struct Node));
		scanf("%s %d",node->name,&(node->time));
		if(head==NULL){
			head = node;
			tail = node;
		}else{
			tail->next = node;
			node->last = tail;
			tail = node;
		}
	}
	tail->next = head;
	head->last = tail;
	
//	while(head!=tail){
//		printf("%s %d\n",head->name,head->time);
//		head = head->next; 
//	}
//	printf("%s %d\n",head->name,head->time);
//	head = head->next; 

	
	while(1){
//		printf("###%s %d\n",head->name,head->time);
		int time = head->time;
		if(time > q){
			head->time -= q;
			globalTime += q;
			head = head->next;
		}else{
			globalTime += time;
			printf("%s %d\n",head->name,globalTime);
			head = head->next;
			if(head == head->next){
				break;
			}
			removeNode(head->last);
		}
		
	}
}
void removeNode(struct Node *node){
	node->last->next = node->next;
	node->next->last = node->last;
	free(node);
}
