#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#define MAX 100005
typedef struct pp{
  char name[100];
  int t;
}P;
void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P x);
P dequeue(void);
P Q[MAX+1],Q2[MAX+1];
int head, tail, n;

int main(){
  int c,time=0;
  char elaps[100];
  int i, q;
  P u;
  initialize();
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }

  while(isEmpty()!=1){
    u=dequeue();
    c=u.t-q;
    if(c>0){
      u.t=c;
      enqueue(u);
      time+=q;
    }
    else{
      time+=u.t;
      printf("%s %d\n",u.name,time);
    }
  }
  
 return 0;
}


void initialize(void){
  head=0;
  tail=0;
}

int isEmpty(void){
  
  if(head==tail)  return 1;
  else return 0;
}

int isFull(void){
  if(head==(tail+1)%MAX) return 1;
  else return 0 ;
  
}

void enqueue(P x){
  if(isFull()==1){
    fprintf(stderr,"??¨?????????????????????????????????\n");
    exit(1);
  }
  Q2[tail]=x;
  if(tail+1==MAX) tail=0;
  else tail++;
}
P dequeue(void){
  P x;
  if(isEmpty()==1){
    fprintf(stderr,"??¨???????????¢?????????????????????\n");
    exit(1);
  }
  x=Q2[head];
  if(head+1==MAX) head=0;
  else head++;
  return x;
}