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

struct Process{
  char name[100];
  int t;
};

struct Process Q[1000];
int n,head=1,tail=1;

void enqueue(struct Process x){
  Q[tail] = x;
  if(tail == n) tail = 1;
  else tail++;
}

struct Process dequeue(){
  struct Process x;

  x = Q[head];

  if(head == n) head = 1;
  else head++;

  return x;
}

int main(void){
  int i,q,cou=0,time=0;
  struct Process k;

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

  while(cou != n){
    k = dequeue();

    if(k.t <= q){
      time += k.t;
      printf("%s %d\n",k.name,time);
      cou++;
    }

    else{
      time += q;
      k.t -= q;
      enqueue(k);
    }    
  }  

  return 0;
}