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

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

Ret Q_s[LEN];
int head, tail,z;

void enqueue_s(Ret x){
  Q_s[tail]=x;
  tail=(tail+1)%LEN;
}

Ret dequeue_s() {
  Ret x=Q_s[head];
  head=(head+1)%LEN;
  return x;
}

int min(int c,int d){return c<d? c:d;}

int main(){
  int times=0,cal;
  int i,y;
  Ret rs;
  
  scanf("%d %d",&z,&y);

  for(i=1;i<=z;i++){
    scanf("%s",Q_s[i].name);
    scanf("%d",&Q_s[i].t);
  }
  head=1;
  tail=z+1;

  while(head!=tail){
    rs=dequeue_s();
    cal=min(y,rs.t);
    rs.t-=cal;
    times+=cal;
    if(rs.t>0)enqueue_s(rs);
    else{
      printf("%s %d\n",rs.name,times);
    }
  }
  return 0;
}

