#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
int queue[MAX];
int head,tail;
void intialize();
void push(int i);
int pop();
int isempty();
int isfull();
typedef struct {
  char name[10];
  int time;
} Process;

void intialize(){
  head=0;
  tail=0;
}
void push(int i){
  if(isfull()){
    printf("overflow\n");
    exit(1);
  }
  queue[tail]=i;
  if(tail+1==MAX)tail=0;
  else tail++;
}
int pop(){
  if(isempty()){
  printf("underflow\n");
  exit(1);
  }
  int x;
  x=queue[head];
  if(head+1==MAX)head=0;
  else head++;
  return x;

}
int isempty(){
  return head==tail;
}
int isfull(){
  return head==(tail+1)%MAX;
}
int main(){
  int n,q;
  int i;
  long int  sum_time=0;
  int now;
 Process process[MAX];
  intialize();
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",process[i].name,&process[i].time);
    push(i);
  }

  while(!isempty()){
    /* printf("queue ");
    for(i=head;i<tail;i++) printf("%d ",queue[i]);
    printf("\n");
    */
    now=pop();
    if(process[now].time<=q) {
      sum_time+=process[now].time;
      printf("%s %ld\n",process[now].name,sum_time);
    }
    else {
      process[now].time-=q;
      sum_time+=q;
      push(now);
    }
  }
  return 0;
}