#include<stdio.h>

#define MAX 100000

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

Process P[MAX];
int head,tail;

int min(int,int);
void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(Process);
Process dequeue(void);

int main(void){
  int n,q,t_sum=0;
  Process tmp;
  int i;

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

  for(i = 0; i < n; i++){
    scanf(" %s %d",P[i].name,&P[i].time);
    enqueue(P[i]);
  }

  while(head != tail){
    tmp = dequeue();
    if(tmp.time == 0) continue;
    t_sum += min(tmp.time,q) == tmp.time ? tmp.time : q;
    tmp.time -= min(tmp.time,q) == tmp.time ? tmp.time : q;
    if(tmp.time != 0){
      enqueue(tmp);
    }
    else{
      printf("%s %d\n",tmp.name,t_sum);
    }
  }
  
  
  return 0;
}

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

void initialize(void){
  head = tail = 0;
}

int isEmpty(void){
  return head == tail;
}

int isFull(void){
  return head == (tail+1) % MAX;
}

void enqueue(Process x){
  if(isFull()){
    fprintf(stderr,"Queue is full\n");
  }
  else{
    P[tail] = x;
    if(tail + 1 == MAX) tail = 0;
    else tail++;
  }
}

Process dequeue(void){
  Process x;
  if(isEmpty()){
    fprintf(stderr,"Queue is empty\n");
    Process T={
      "error",
      0,
    };
    return T;
  }
  x = P[head];
  if(head + 1 == MAX) head = 0;
  else head++;
  return x;
}
  

