#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define TRUE 1
#define FALSE 0
#define MAX 100005

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


int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

int head=0,tail=0,n;
P Q[MAX+1];

int main()
{
  int elaps = 0,c;
  int i,q;
  P u;

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

  for(i = 0 ; i < n ; i++ )
    {
      scanf("%s",u.name);
      scanf("%d",&u.time);
      if(u.time < 1 || u.time > 50000 || strlen(u.name) < 1 || strlen(u.name) > 10) return 0;
      
      enqueue(u);
    }

  
  while(n > 0)
    {
      u = dequeue();

      c = u.time - q;

      if(c <= 0)
	{
	  elaps += u.time;
	  n--;
	  printf("%s %d\n",u.name,elaps);
	}
      else
	{
	  u.time -= q;
	  elaps += q;
	  enqueue(u);
	}
    }

  

  return 0;
}

int isEmpty()
{
  if(head == tail) return TRUE;
  else return FALSE;
}

int isFull()
{
  if(head == (tail + 1) % MAX) return TRUE;
  else return FALSE;
}

void enqueue(P x)
{
  if(isFull()) exit(1);

  Q[tail] = x;

  if(tail + 1 == MAX) tail = 0;
  else tail++;
}

P dequeue()
{
  P x;
  if(isEmpty()) exit(2);

  x = Q[head];

  if(head + 1 == MAX) head = 0;
  else head++;

  return x;
}

