#include<stdio.h>
#define MAX 1000000

typedef struct pp{
  char name[10];
  int time;
} P;

P Q[MAX];
int head, tail, n;

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

int isEmpty(){
  return head == tail;
}

int isFull(){
  return head == (tail + 1) % MAX;
}

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

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

int min(int a, int b){
  return a < b ? a : b;
}

int main(){
  int elapsed_time=0;
  P  remaining;
  int i,q,c;

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

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

  head = 1;
  tail = n+1;

  while(head != tail){
    remaining = dequeue();
    c = min(q,remaining.time);
    remaining.time -= c;
    elapsed_time += c;
    if(remaining.time > 0){
      enqueue(remaining);
    }
    else {
      printf("%s %d\n",remaining.name,elapsed_time);
    }
  }

  return 0;
}

