#include<stdio.h>
#define MAX 100000
typedef struct{
  char name[10];
  int time;
}process;
void enqueue(process);
process dequeue(void);
int head=0,tail=0,q;
process p[MAX];

int main()
{
  process x;
  int n,i,t=0;

  scanf("%d%d",&n,&q);
  for(i=0; i<n; i++)  {
    scanf("%s%d",x.name,&x.time);
    enqueue(x);
  }

  while(head!=tail) {
    if(p[head].time > q) {
      p[head].time = p[head].time-q;
      t += q;
      enqueue(dequeue());
    }
    else if(p[head].time <= q) {
      t += p[head].time;
      printf("%s %d\n",p[head].name,t);
      dequeue();
    }
  }
    
  return 0;
}

void enqueue(process x)
{
  p[tail] = x;
  if(tail+1 == MAX-1) tail = 0;
  else tail++;
}