#include <stdio.h>
#define N 100005

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

void enqueue(PROCESS );
PROCESS dequeue();


PROCESS QUEUE[N];

int head = 0,tail;

int main()
{
  int num,q,cnt,t = 0,j = 0;
  scanf("%d%d",&num,&q);
  for(int i = 0; i < num; i++){
    scanf("%s%d",QUEUE[i].name,&QUEUE[i].time);
  }
  tail = num;
  while(cnt != num){
    if(QUEUE[head].time > q){
      QUEUE[head].time -= q;
      t+=q;
      enqueue(dequeue());
    }
    else {
      t += QUEUE[head].time;
      printf("%s %d\n",QUEUE[head].name,t);
      dequeue();
      cnt++;
    }
  }
  return 0;
}

void enqueue(PROCESS x){
  QUEUE[tail] = x;
  tail = (tail+1)%N;
}

PROCESS dequeue(){
  PROCESS tmp;
  tmp = QUEUE[head];
  head = (head+1)%N;
  return tmp;
}

