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

typedef long ELEM;

#define QUEUE_SIZE 100000

struct process{
	char* name;
	ELEM time;
};

struct process queue[QUEUE_SIZE];

int n;
int front;
int rear;

#define next(a) ((a+1) % QUEUE_SIZE)

void error(char *s);
void init();
struct process dequeue();
void enqueue(char *s, ELEM x);
int empty();

int main(void){
	int i,j;
	long x;
	struct process temp;
	int n, q, elap=0;
	char s[10];

	init();

	scanf("%d",&n);
	scanf("%d",&q);

	for(i=0;i<n;i++){
		scanf("%s %ld",s, &x);
		enqueue(s,x);
	}

	while(1){
//		fprintf(stderr, "check1\n");
		temp=dequeue();
		if(temp.time>q){
			enqueue(temp.name,temp.time-q);	
			elap+=q;
//			fprintf(stderr, "check2\n");
		}else{
			elap+=temp.time;
//			fprintf(stderr, "check3\n");
			printf("%s %d\n",temp.name, elap);
		}
		if(empty()){
//			fprintf(stderr, "check4\n");
			break;
		}
	}

	printf("\n");

	return 0;
}

void error(char *s){
	fprintf(stderr,"%s\n",s);
	exit(1);
}

void init(){
	front=rear=0;
}

struct process dequeue(){
	struct process x;
	if(front == rear) error("queue underflow");
	x = queue[front];
	front = next(front);
	return x;
}

void enqueue(char* s,ELEM x){
	if(next(rear) == front) error("queue overflow");
	queue[rear].name = (char*)malloc(sizeof(char)*strlen(s));
	strcpy(queue[rear].name,s);
	queue[rear].time = x;
	rear = next(rear);
}

int empty(){
	return front == rear;
}