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

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

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

void enqueue(P x){

  if(head == (tail + 1) % MAX){
    printf("over flow\n");
    exit(1);
  }

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

P dequeue(){

  P x;

  if(head == tail){
    printf("over flow\n");
    exit(1);
  }

  x = Q[head];
  if(head + 1 == MAX) head = 0;
  else head++;

  return x;
  
}

int main(){
  
  int i,q,data;
  int alltime=0;
  P u;
 

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

  for(i = 1; i <= n; i++){
    scanf("%s", u.name);
    scanf("%d", &u.time);
    enqueue(u);
  }
  
  data=n;
  
  while(data>0){

    u=dequeue();

    if(u.time<=q){
      alltime+=u.time;
      printf("%s %d\n",u.name,alltime);
      data--;
    }else{
      u.time=u.time-q;
      alltime+=q;
      enqueue(u);
    }
    
  }

  return 0;
  
}


