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

#define MAX 1001

typedef struct{
  char name[MAX];
  int time;
} Process;

void initialize(void);
void enqueue(int);
int dequeue(void);
int isEmpty(void);
int isFull(void);

int head,tail;
Process prc[MAX];

int main(){
  int n,q,i,prcIndex,prcTime=0;

  initialize();
  //in
  scanf("%d%d",&n,&q);

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

  //calculation
  while(head!=tail){
    prcIndex = dequeue();
    if(prc[prcIndex].time>q){
      prcTime += q;
      prc[prcIndex].time -= q;
      enqueue(prcIndex);
    } else {
      prcTime += prc[prcIndex].time;
      printf("%s %d\n",prc[prcIndex].name,prcTime);
    }
  }
  
  return 0;
}

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

void enqueue(int x){
  if(isFull()){
    printf("Overflow!\n");
    exit(1);
  }
  prc[tail]=prc[x];
  if(tail+1== MAX) tail = 0;
  else tail++;
}

int dequeue(void){
  int x;

  if(isEmpty()){
    //printf("Underflow!\n");
    //exit(2);
  }
  x=head;
  if(head+1==MAX) head = 0;
  else head++;
  
  return x;
}

int isEmpty(void){
  if(head == tail) return 1;
  else return 0;
}

int isFull(void){
  if(head == (tail+1) % MAX) return 1;
  else return 0;
}