#include<stdio.h>
#include<string.h>
#define A 100000

typedef struct {
  char name[100];
  int time;
}pro;

pro que[A];
int head,tail,n;

void enter(pro );
pro out(void);
int minimam(int,int);

void enter(pro a)
{
  que[tail] = a;
  tail = (tail + 1) % A;
}

pro out(void)
{
  pro a = que[head];
  head = (head +1) % A;
  return a;
}

int minimam(int a,int b)
{
  return a < b ? a:b;
}

int main()
{
  int i,q,x,timed=0;
  pro cess;

  scanf("%d%d",&n,&q);
  
  head = 1;
  tail = n + 1;

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

  while(head != tail) {
    cess = out();
    x = minimam(q,cess.time);
    cess.time -= x;
    timed += x;
    if(cess.time > 0){
      enter(cess);
    }else{
      printf("%s %d\n",cess.name,timed);
    }
  }

  return 0;
}
      
    
    

