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

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

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

void enqueue(P );
P dequeue();
int calc(int,int);

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

  for ( i = 1; i <= n; i++){
    scanf("%s %d", Q[i].name,&Q[i].t);

  }

  head = 1;
  tail = n+1;
  
  while(head != tail){
    u = dequeue();
    t1 = calc(q,u.t);
    u.t = t1;
    t2 += t1;

    if(u.t > 0){
      enqueue(u);
    }
    
    else{
      printf("%s %d\n", u.name ,t2);
    }
 
  }
  return 0;
}
P dequeue(){
	P x;
	x = Q[head];
	if((head+1)>n+1) head = 1;
	else head++;
	return x;
      }
void enqueue(P x){
  Q[tail] = x;
  if((tail+1) == n+2) tail = 1;
  else tail++;
}
int calc(int x, int y){
  if(x >= y)return y;
  else return x;
}