#include <stdio.h>
#define N 100005

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

void enqueue(data );
data dequeue();

data Q[N];

int head=0,tail;

int main()
{
  int i,n,q,cnt,t=0;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q[i].name,&Q[i].time);
  }
  tail = n;
  while(cnt != n){
    if(Q[head].time > q){
      Q[head].time -= q;
      t+=q;
      enqueue(dequeue());
    }
    else {
      t += Q[head].time;
      printf("%s %d\n",Q[head].name,t);
      dequeue();
      cnt++;
    }
  }
  return 0;
}

void enqueue(data x){
  Q[tail] = x;
  tail = (tail+1)%N;
}

data dequeue(){
  data tmp;
  tmp = Q[head];
  head = (head+1)%N;
  return tmp;
}

