#include<stdio.h>
#include<stdbool.h>

#define MAX 10000

typedef struct {
  int id, time;
} State;

State queue[MAX];
int head, tail;

void push(int id,int tm) {
  queue[tail].id = id, queue[tail].time = tm;
  tail = ((tail+1==MAX)?0:tail+1);
}

State pop() {
  State v = queue[head];
  head = ((head+1==MAX)?0:head+1);
  return v;
}

inline bool empty() { return (tail - head) == 0; }

int n, q;
char P[MAX][200];

void exec() {
  int total_time = 0;
  while( !empty() ) {
    if( queue[head].time > q ) {
      queue[head].time -= q;
      State tmp = pop();
      push(tmp.id,tmp.time);
      total_time += q;
    } else {
      total_time += queue[head].time;
      printf("%s %d\n",P[queue[head].id],total_time);
      pop();
    }
  }
}

int main() {
  int i, T;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;++i) {
    scanf(" %s %d",&P[i][0],&T);
    push(i,T);
  }
  exec();
  return 0;
}