#include <stdio.h>
#include <stdlib.h>
#define N 100000

typedef struct data{
  char name[10];
  int time;
}Data;

Data Q[N+1];
int head=0,tail=0,n;
int isEmpty(void);
int isFull(void);
void enqueue(Data);
Data dequeue(void);

int main(){
  int n,q,i,T=0;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q[i].name,&Q[i].time);
    tail=i+1;
  }
  while(isEmpty()!=1){
      if(Q[head].time>q){
	T+=q;
	Q[head].time=Q[head].time-q;
	enqueue(dequeue());
      }
      if(Q[head].time<=q){
	T+=Q[head].time;
	printf("%s %d\n",Q[head].name,T);
	dequeue();
    }
  }
  return 0;
}
void enqueue(Data person){
  if(isFull()==1){
    printf("overflow");
    exit(1);
  }
  Q[tail]=person;
  if(tail+1==N)tail=0;
  else tail++;
}
Data dequeue(void){
  Data person;
  if(isEmpty()==1){
    printf("underflow");
    exit(2);
  }
  person=Q[head];
  if(head+1==N)head=0;
  else head++;
  return person;
}
		
int isEmpty(){
   return head == tail;
    }

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

