/*
  キュー(ALDS1-3_B)
  2018/08/31
*/

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

#define LEN 100005

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

Process queue[LEN];
int head,tail,n;
char line[100];

/*キューに入れる*/
void enqueue(Process x) {
  queue[tail] = x;
  tail = (tail + 1) % LEN;
}

Process dequeue(){
  Process x = queue[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b){
  return a < b ? a : b;
}
int main(void){
  int elaps = 0,c;
  int i,q;
  Process use;

  fgets(line,sizeof(line),stdin);
  sscanf(line,"%d %d",&n, &q);

  for(i=0;i<n;i++){
    fgets(line,sizeof(line),stdin);
    sscanf(line,"%s %d",queue[i].name,&queue[i].time);
  }
  head = 0; tail = n;

  while(head != tail){
    use = dequeue();
    c = min(q,use.time);
    use.time -= c;
    elaps += c;
    if(use.time > 0) enqueue(use);
    else printf("%s %d\n",use.name , elaps);
  }
  
  
  return 0;
}

