#include <stdio.h>
#define N 100000

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

queue Q[N];
int head,tail,n;

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

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

int min(int a,int b){return a < b ? a : b;}

int main(){
  queue x;
  int q,i;
  int pass = 0,c;

  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].time);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    x=dequeue();
    c=min(q,x.time);
    x.time-=c;
    pass+=c;
    if(x.time>0)enqueue(x);
    else printf("%s %d\n",x.name,pass);
  }

  return 0;
}

