#include<stdio.h>
#include<stdlib.h>
#define MAX 1000000

typedef struct {
  char name[10];
  int time;
  int flag;
}Pro;

void enqueue(Pro);
  
int n,head,tail;
Pro queue[MAX];

int main(){
  int i,q,record,total;
  Pro v;
  
  scanf("%d %d",&n,&q);
  if(n < 1 || 1000000 < n)exit(0);
  if(q < 1 || 1000 < q)exit(0);

  head = 1;
  tail = head;
  total = 0;

  for(i = 1; i <= n; i++){
    scanf("%s %d",queue[i].name,&queue[i].time);
    queue[i].flag = 0;
    if(queue[i].time < 1 || 50000 < queue[i].time)exit(0);
    total += queue[i].time;
    if(total < 1 || 1000000 < total)exit(0);
  }
  tail += n ;
  
  record = 0;
  
  while(1){
    
    if(queue[head].time - q <= 0){
      record += queue[head].time;
      printf("%s %d\n",queue[head].name,record);
      head = (head + 1)%MAX;
    }
    else if(queue[head].time - q > 0){
      record += q;
      queue[head].time = queue[head].time - q;
      v = queue[head];
      head = (head + 1)%MAX;
      enqueue(v);
    }
    if(head == tail)break;
  }
  
  return 0;
}

void enqueue(Pro v){
  
  queue[tail] = v;
  tail = (tail + 1)%MAX;
  
}


