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

void enqueue(int index);
int dequeue(void);

int Q[1001];
int lastQ;

char name[1001][11];
int time[1001];

main(){

  int i, index;
  char inName[11];
  int inTime;
  int elapsedTime = 0;
  int n,q;

  lastQ = 0;

  scanf("%d %d",&n,&q);

  for(i=0; i<n; i++){
    scanf("%s %d",inName,&inTime);

    // storage
    strcpy(name[i],inName);
    time[i] = inTime;

    enqueue(i);
  }

  while(n!=0){

    for(i=0; i<lastQ; i++){
      printf("    %s:%d\n",name[Q[i]],time[Q[i]]);
    }

    index = dequeue();

    time[index] -= q;
    elapsedTime += q;

    if(time[index] <= 0){

      elapsedTime += time[index];
      printf("%s %d\n",name[index],elapsedTime);
      n--;

    }else{

      enqueue(index);

    }

  }

  return 0;

}

void enqueue(int index){

  Q[lastQ++] = index;

}

int dequeue(void){

  int i,tmp = Q[0];

  lastQ--;

  for(i=0; i<lastQ; i++){
    Q[i] = Q[i+1];
  }

  return tmp;

}