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

int h,t,A1[N];
char A2[N][10];

void enqueue(char *l, int q)
{
  int i = 0;

  
  if(isFull()){
    fprintf(stderr,"overflow!\n");
    exit(2);
  }

  
  A1[t] = q;
  strcpy(A2[t],l);
  if(t + 1 == N) t = 0;
  else t++;
}

int dequeue()
{
  int f;

  if(isEmpty()){
    fprintf(stderr,"underflow!\n");
    exit(1);
  }

  f = h;
  if(h + 1 == N) h = 0;
  else h++;

  
  return f;
}

int isEmpty()
{
  return h == t;

}

int isFull()
{
  return h == (t + 1) % N;
}

void roundschedule(int d, int b)
{
  int i,num,s;
  int total = 0;
  char B[10];



  for(i=0;i<d;i++){
    scanf("%s%d",B,&num);
    enqueue(B,num);
  }

  while(!isEmpty()){
    num = dequeue();
    if(b>=A1[num]){
      total += A1[num];
      printf("%s %d\n",A2[num],total);
    }

    else{
      s = A1[num] - b;
      total += b;
      enqueue(A2[num],s);
    }
  }
}

int main()
{
  int n,m;

  scanf("%d%d",&n,&m);
  roundschedule(n,m);

  return 0;
}

