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

typedef struct proc
{
  char name[100];
  int t;
}process;

int n;
int head = 0, tail = 0;
process queue[LEN + 1];

void enqueue(process x)
{
  queue[tail] = x;
  if(tail + 1 == LEN) tail = 0;
  else tail++;
}

void dequeue()
{
  if(head + 1 == LEN) head = 0;
  else head++;
}

int main()
{
  int elaps = 0;
  int i, q;
  process tmp;

  scanf("%d %d", &n, &q);

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

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