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

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

P Q[MAX+1];
int head=1, tail=0, n;


int isEmpty(int head, int tail){
  if(head == tail) return head;
  else return -1;
}
int isFull(int head, int tail){
  if(head == (tail+1)%MAX) return head;
  else return -1;
}
void enqueue(P x){
  if(isFull(head, tail) == head){
    fprintf(stderr, "overflow!\n");
    exit(1);
  }
  Q[tail] = x;
  if(tail+1 == MAX) tail = 0;
  else tail++;
}

P dequeue(){
  P x;
  if(isEmpty(head, tail) == head){
    fprintf(stderr, "underflow!\n");
    exit(1);
  }
  //printf("Q[tail] is %s, %d\n", Q[tail-1].name, Q[tail-1].t);
  x = Q[head];
  if(head+1 == MAX){
    head = 0;
  } else{
    head++;
  }
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d", &n, &q);
  tail = n+1;
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  while(1){
    if(head == tail)break;
    if(Q[head].t-q <= 0){
      //printf("if   Worked!\n");
      u = dequeue();
      elaps += u.t;
      printf("%s %d\n", u.name, elaps);
    } else{
      //printf("else Worked!\n");
      elaps += q;
      u = dequeue();
      u.t -= q;
      enqueue(u);
    }
  }

  
  return 0;
}

