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

typedef struct 
{
  char task[10];
  int time;
}t_queue;

t_queue q[100000];

int head = 0;
int tail = 0;

void enqueue(char name[], int time)
{
  strcpy(q[head].task, name);
  q[head].time = time;
  head++;
  if(head > 100000-1) head = 0;
}

t_queue deque(void)
{
  t_queue data;
  data = q[tail];
  tail++;
  if(tail > 100000-1) tail = 0;
  return data;
}

int main(int argc, char const *argv[])
{
  int n, quontime, task_time;
  char task_name[10];
  int total_time = 0;

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

  for(int i = 0; i < n; i++){
    scanf(" %s %d",task_name,&task_time);
    enqueue(task_name, task_time);
  }

  while(head != tail){
    t_queue now_q = deque();
    if(now_q.time - quontime > 0){
      total_time += quontime;
      now_q.time -= quontime;
      enqueue(now_q.task, now_q.time);
    } else {
      total_time += now_q.time;
      printf("%s %d\n", now_q.task, total_time);
    }
  }

  return 0;
}

