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

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

P Q[LEN+1];
int head=0, tail=0, n;

void enqueue(P x){
  Q[tail++]=x;
  if(tail>LEN) tail=0;
}

P dequeue(){
  P x;
  
  if(head==tail){
    x.t=-1;
    return x;
  }
  
  x=Q[head++];
  if(head>LEN) head=0;
  return x;
}


int main(){
  int e , c=0;
  int i, q;
  P u,p;
  scanf("%d %d", &n, &q);

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

  while( (p=dequeue()).t!=-1){
    if(p.t>e){
      c+=e;
      p.t-=e;
      enqueue(p);
    }

    else{
      c+=p.t;
      printf("%s %d\n",p.name,c);
      e=q;
    }
  }
  
  return 0;
}

