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

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

P *Q;
int head,tail,n;

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

bool isEmpty(){
  if(head == tail) return true;
}

bool isFull(){
  if(head == (tail+1) % n) return false;
}

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

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

int main(){
  int elaps=0,c;
  int i,q;
  P u;

  scanf("%d %d",&n,&q);
  Q = (P *)malloc(sizeof(P) * (n+1));

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

  while(isEmpty() != false){
    printf("test\n");
    u = dequeue();
    printf("%s\n",u.name);
    if(u.t - q <= 0){
      printf("%s %d\n",u.name,elaps+(u.t));
      elaps += u.t;
    }
    else{ 
      printf("test\n");
      u.t -= q;
      elaps += q;
      enqueue(u);
    }
  }

  free(Q);

  return 0;
}