#include<stdio.h>
#include<string.h>
#define LEN 1000000
typedef struct pp{
  char name[100];
  int t;
}P;
P Q[LEN+1];
int main(){
  int n,i,q,s=0,l,c=0;
  scanf("%d %d",&n,&q);
  for (i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  i=1;
  l=n;
  while(1){
    if(Q[i].t>q){
      s+=q;
      strcpy(Q[l+1].name, Q[i].name);
      Q[l+1].t=Q[i].t-q;
      l++;
    } else {
      sum += Q[i].t;
      printf("%s %d\n",Q[i].name,s);
      c++;
    }
    i++;
    if(c==n) break;
  }   
  return 0;
}