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

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

P Q[LEN+1];
int head,tail,n;

void enqueue(P x){
  if(head==(tail+1)%(LEN+1)){
    printf("Error!Full!\n");
    exit(1);
  }
  Q[tail]=x;
  if(tail+1==(LEN+1))tail=0;
  else tail++;
}

P dequeue(){
  P x;
  if(head==tail){
    printf("Error!Empty!\n");
    exit(2);
  }
  x=Q[head];
  if((head+1)==(LEN+1))head=0;
  else head++;
  return x;
}

int main(){
  int elaps=0,c,total=0,count=0;
  int i, q;
  P u;
  scanf("%d%d",&n,&q);

  head=tail=0;
  for (i=1;i<=n; i++){
    scanf("%s",u.name);
    scanf("%d",&u.t);
    enqueue(u);
    total+=u.t;
  }
  
  while(count!=total){
    u = dequeue();
    if(u.t>q){
      u.t-=q;
      count+=q;
      enqueue(u);
    }
    else if(u.t<=q){
      count+=u.t;
      printf("%s %d\n",u.name,count);
    }
  }

  return 0;
}
  

