#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define QUEUESIZE 100000
typedef struct{
  int num;
  char str[10]; 
}Prs;
typedef Prs ELEM;
ELEM queue[QUEUESIZE];
int head,tail;
int next(int);
void init();
void enqueue(ELEM);
ELEM dequeue();
int empty();

int main(){
  int i,n=0,q=0,rec=0;
  ELEM *data,j;
  init();
  scanf(" %d%d",&n,&q);
  data = (ELEM *)malloc(n * sizeof(ELEM));

  for(i=0;i<n;i++){
    scanf("%s %d",&data[i].str,&data[i].num);
	enqueue(data[i]);
  }
  i=0;
  while(empty()){
	  j = dequeue();
	  if(j.num > q){
		  j.num -= q;
		  rec += q;
		  enqueue(j);
	  }else{
		  rec += j.num;
		  data[i].num = rec;
		  strcpy(data[i].str,j.str);
		  i++;
	  }
  }
  i=0;
  while(i<n){
	  printf("%s %d\n",data[i].str,data[i].num);
	  i++;
  }

  return 0;
}

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

int next(int a){
	return ((a+1)%QUEUESIZE);
}

int empty(){
	return head != tail;
}

void enqueue(ELEM a){
	queue[tail] = a;
	tail = next(tail);
}

ELEM dequeue(){
	ELEM a;
    a = queue[head];
	head = next(head);
	return a;
}
