#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100000
#define L 10
#define TRUE 1
#define FALSE 0
int head,tail;
int Q[N];

void initialize();
void enqueue();

int main(){
  int i,j,n,q,a;
  char name[N][L];
  int sumtime=0;
  char temp[L];
  
  scanf("%d%d",&n,&q);
  
  initialize();
  
  for(i=0;i<n;i++){
    scanf("%s%d",name[i],&Q[i]);
    tail++;
  }


  while(isEmpty()!= 1){
    if(Q[head]-q>0){
      strcpy(name[tail],name[head]);
      sumtime += q;
      Q[head]-= q;
      a = dequeue(Q[head]);
      enqueue(a);

    }
    else{
      sumtime += Q[head];
      a = dequeue(Q[head]);
      printf("%s %d\n",name[head-1],sumtime);
    }
    
  }

  return 0;
}

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

int isEmpty(){
  if(head == tail){
    return TRUE;
  }
  else return FALSE;
}


void enqueue(int x){
  
  Q[tail] = x;
  if(tail+1 == N){
    tail = 0;
  }
  else{
    tail++;
  }
}

int dequeue(){
  int x;
  x = Q[head];
  if((head +1) == N){
    head = 0;
  }
  else {
    head++;
  }
  return x;
}

