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

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

Pin Q[N+1],a[N+1];
int head=0, tail=0, n;

void enque(Pin x){
 Q[tail]=x;
  if(tail+1==N){
    tail=0;
  }
  else tail++;
}

Pin deque(){
 Pin x;
  x=Q[head];
    if(head+1==N){
      head=0;
    }
    else{
      head++;
    }
  return x;
}


int main(){
  int a = 0, c;
  int i, q,j=0;
  Pin u;
  scanf("%d %d", &n, &q);

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

  while(j!=n){
    u=deque();
    if(u.t<=q){
      a+=u.t;
     printf("%s %d\n",u.name,a);
     j++;
    }
    else {
	u.t-=q;
	a+=q;
	enque(u);

	  }
  }
  return 0;
}