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

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

int head=0,end,count=0,n,q;
process* p;

void deQ(void);
void enQ(void);

int main(){
  int i;
  scanf("%d%d",&n,&q);
  end=n;
  p=(process *)malloc(sizeof(int)*(n+1));
  for(i=0;i<n;i++){
    scanf("%s",p[i].name);
    scanf("%d",&p[i].time);
  }
  while(head!=end){
    deQ();
    enQ();
  }
  
  return 0;
}


void deQ(){
  if(p[head].time<=q){
    count+=p[head].time;
    p[head].time=0;
    printf("%s %d\n",p[head].name,count);
  }
  else{
    p[head].time-=q;
    count+=q;
  }
  head++;
  if(head==n+1)
    head=0;
}

void enQ(){
  int ead;
  if(head==0)
    ead=n;
  else
    ead=head-1;
  if(p[ead].time!=0){
    p[end]=p[ead];
    end++;
  }
  if(end==n+1)
    end=0;
}