#include <stdio.h>
#include <stdlib.h>
#define MAX 1000001

typedef struct{
  int time;
  char name[10];
} P;

void enqueue(P);
void dequeue(void);
int head=0,tail=0,x;


P queue[MAX];

int main()
{
  int n,q,i,sum=0;  /* q=クオンタム */
  scanf("%d %d",&n,&q);
  tail = n;
  for(i=0 ; i<n ; i++)
  {
    scanf("%s %d",queue[i].name,&queue[i].time);
  }

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

void enqueue(P q)
{
  if(head == (tail + 1)% MAX) exit(1);
  queue[tail]=q;
  if(tail + 1 == MAX) tail=0;
  else tail++;
}

void dequeue(void)
{
  if(head == tail) exit(1);
  if(head + 1 == MAX) head = 0;
  else head++;
}

