#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x)
{
	int next;
	Q[head] = x;
	next = (head+1)%(LEN+1);
	if(next != tail){
		if(next == 0) next = 1;
		head = next;
	}
	return;
}

P dequeue()
{
	int next;
	next = (tail+1)%(LEN+1);
	if(next != head){
		if(next == 0) next = 1;
		tail = next;
		return(Q[tail]);
	}
}

int empty()
{
	int next;
	next = (tail+1)%(LEN+1);
	if(next == head){
		return(0);
	}
	return(1);
}


int main()
{
  int elaps = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  head = 1;
  tail = 0;
  for ( i = 1; i <= n; i++){
    scanf("%s", &u.name);
    scanf("%d", &u.t);
	enqueue(u);
  }
  while(empty()){
	  u = dequeue();
	  u.t -= q;
	  elaps += q;
	  if(0 < u.t){
		  enqueue(u);
	  }else{
		  elaps += u.t;
		  printf("%s %d\n", u.name, elaps);
	  }
  }
  
  return 0;
}