#include<stdio.h>

#define T 1
#define MAX 100005

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

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

P Q[MAX+1];
int head,tail;


int main(){
  int i,n,q,elaps = 0,a,b,c;
  P u;
  initialize();
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
  }
  head = 0;
  tail = n;
  while(head != tail){
    u=dequeue();
    if(u.t<=q){
      b=u.t;
      elaps += b;
      printf("%s %d\n",u.name,elaps);
    }
    else{
      b=q;
      u.t = u.t - q;
      enqueue(u);
      elaps += b;
    }

  }
  return 0;
}

void initialize(void){
  head = tail = 0;
}

int isEmpty(void){
  if(head == tail){
    return T;
  }
  return 0;
}

int isFull(void){
  if(head == (tail+1)%MAX){
    return T;
  }
  return 0;
}

void enqueue(P x){
  if(isFull()==T){
    fprintf(stderr,"overflow\n");
  }
  Q[tail] = x;
  if(tail+1 ==MAX){
    tail = 0;
  }
  else{
    tail++;
  }
}

P dequeue(void){
 P x;
  if(isEmpty()==T){
    fprintf(stderr,"underflow\n");
  }
  x = Q[head];
  if(head + 1 ==MAX){
    head = 0;
  }
  else{
    head++;
  }
  return x;
}

