#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  if(isFull() == 1){
    fprintf(stderr,"?????????????????????\n");
    exit(1);
  }

    Q[tail] = x;

    if((tail + 1) == (LEN+1)) tail = 0;
    else tail++;
}

P dequeue(void){
  P x;
  if(isEmpty() == 1){
    fprintf(stderr,"??¢??????????????????\n");
    exit(1);
  }
   
  x = Q[head];

  if((head + 1) == (LEN+1)) head = 0;

  else head++;

  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  initialize();
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n+1;

  while(1){
    u = dequeue();
    c = u.t;
    if((u.t -= q) > 0){
      enqueue(u);
      elaps += q;
    }
    else {
      elaps += c;
      printf("%s %d\n",u.name,elaps);
    }
    if(isEmpty() == 1) break;
  }
  
  return 0;
}

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

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

 int isFull(void)
 {
   if(head == (tail + 1) % (LEN+1)) return 1;
   return 0;
 }