#include<stdio.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 initialize(){
  head = tail = 0;
}

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

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

void enqueue(P x){
  if(isFull()) return;
  Q[tail] = x;
  if(tail+1 == LEN) tail = 0;
  else tail++;
}

P dequeue(){
  P x;
  if(isEmpty()) return;
  x = Q[head];
  if(head+1 == LEN) head = 0;
  else head++;
  return x;
}

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

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



  return 0;
}