#include <stdio.h>

#define MAX 100005

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

P Q[MAX+1];
int head,tail,N;

void enqueue(P);
P dequeue(void);
int mini(int,int);

int main(){
  int fullt = 0;
  int c,i,prot;
  P pro;

  scanf("%d %d",&N,&prot);

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

  head = 1;
  tail = N + 1;

  while(head != tail){
    pro = dequeue();
    c = mini(prot,pro.t);
    pro.t -= c;
    fullt += c;

    if(pro.t > 0){
      enqueue(pro);
    }

    else{
      printf("%s %d\n",pro.name,fullt);
    }
  }

  return 0;
}

void enqueue(P pro){
  Q[tail] = pro;
  tail = (tail + 1) % MAX;
}

P dequeue(void){
  P pro = Q[head];

  head = (head + 1) % MAX;

  return pro;
}

int mini(int a,int b){

  if(a > b)return b;

  else return a;
}
             

