#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 100000

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

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

int Empty(){
  if(head == tail)
    return 1;
  else return 0;
}

void enqueue(P x){
  Q[tail] = x;
  tail++;
}

void ini(){
  head = 0;
  tail = n+1;
}


int main(){
  int elaps = 0, c, count=1;
  int i, q;
  scanf("%d %d", &n, &q);
  int A[n+1];
  
  for(i=1;i<=n;i++){
    w[i].t = 0;
  }
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  ini();

  i=1;
  while(count != n+1){
    if(Q[i].t > q){
      Q[i].t=(Q[i].t-q);
      elaps+=q;
      enqueue(Q[i]);
      i++;
    }
    else if(Q[i].t<=q){
      elaps+=Q[i].t;
      w[count].t=elaps;
      strcpy(w[count].name,Q[i].name);
      i++;
      count++;
    }
  }
    for(i=1;i<=n;i++){
      printf("%s %d\n",w[i].name,w[i].t);
    }
	
  
  return 0;
}

