#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int head;
int tail;
typedef struct{
  char name[11];
  int time;
}Q;
void enqueue(Q *a,Q b);
Q dequeue(Q *a);
int main()
{
  int n,m,k=0,i,sum=0;
  head=0;
  scanf("%d %d",&n,&m);
  Q q[1000],arr[n];
  tail=n-1;
  for(i=0;i<n;i++){
    scanf("%s",q[i].name);
    scanf("%d",&q[i].time);
  }
  i=0;
  while(1){
    if(k==n)break;
    if(m>=q[i].time){
      sum+=q[i].time;
      arr[k]=dequeue(q);
      arr[k].time=sum;
      k++;
    }else{
      sum+=m;
      q[i].time=q[i].time-m;
      enqueue(q,dequeue(q));
    }
    i++;
  }
  for(i=0;i<n;i++){
    printf("%s %d\n",arr[i].name,arr[i].time);
  }
  return 0;
}
void enqueue(Q *a, Q b){
    tail=tail+1;
    a[tail]=b;
}
Q dequeue(Q *a){
  Q x;
  x=a[head];
    head=head+1;
    return x;
}
