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

#define N 100000

int head, tail, qi[N];

char qc[N][10];

void enqueue(char *s, int x){

  int i = 0;

  if(isFull()){
    fprintf(stderr,"オーバーフロー\n");
    exit(2);
  }

  qi[tail] = x;

  strcpy(qc[tail],s);

  if(tail + 1 == N){
    tail = 0;
  }

  else{
    tail++;
  }

}

int dequeue(){

  int x;

  if(isEmpty()){
    fprintf(stderr,"アンダーフロー\n");
    exit(1);
  }

  x = head;

  if(head + 1 == N){
    head = 0;
  }

  else{
    head++;
  }

  return x;

}

int isEmpty(){

  return head == tail;

}

int isFull(){

  return head == (tail + 1) % N;

}

void roundschedule(int n, int q){

  int i,num,a;

  int total = 0;

  char p[10];

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

    enqueue(p,num);
  }

  while(!isEmpty()){

    num = dequeue();

    if(q>=qi[num]){
      total += qi[num];
      printf("%s %d\n",qc[num],total);
    }

    else{
      a = qi[num] - q;
      total += q;
      enqueue(qc[num],a);
    }

  }

}


int main(){

  int n,q;
  scanf("%d%d",&n,&q);
  roundschedule(n,q);
  
  return 0;

}



