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

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

PROCESS q[100000];
int head,tail;

void enqueue(PROCESS);
PROCESS dequeue(void);
int min(int,int);

int main()
{
  int n,q_main,i,time=0,c;
  PROCESS p;

  head = 1;
  
  scanf("%d %d",&n,&q_main);
  if(n<1 || n>100000) exit(1);
  if(q_main<1 || q_main>1000) exit(2);

  tail = n+1;

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

  while(head != tail){
    p = dequeue();
    c = min(q_main,p.time);
    p.time -= c;
    time += c;
    if(p.time > 0)
      enqueue(p);
    else
      printf("%s %d\n",p.name,time);
  }
    
  return 0;
}
  
void enqueue(PROCESS p)
{
  q[tail]=p;
  tail=(tail+1)%100000;
}

PROCESS dequeue()
{
  PROCESS p=q[head];

  head=(head+1)%100000;
  return p;
}

int min(int x,int y)
{
  if(x<y)
    return x;
  else
    return y;

  /* return x>y ? y : x; */
}

