#include<stdio.h>
#include<string.h>

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

int main(void){

    int n,q;
    int time=0,k=0,end;
    scanf("%d %d",&n,&q);
    task a[1000000];

    for(int i=0;i<n;i++){
      scanf("%s %d",&a[i].name,&a[i].time);
    }
    end=n-1;

    for(int i=0;k<n;i++){
      if(a[i].time>q){
        a[i].time-=q;
        time+=q;
        a[++end]=a[i];
      }
      else{
        time+=a[i].time;
        printf("%s %d\n",a[i].name,time);
        k++;
      }

    }



    return 0;




}

