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

#define LEN 100005
#define TRUE 1
#define FALSE 0
#define MAX 100

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

P Q[LEN+1];
int head, tail, n;

void initialize(void);
int Empty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);


int main(){
  P u;
  int elaps = 0, n;
  int i, q;
 
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", u.name);
    scanf("%d", &u.t);
    enqueue(u);
  }

  while(head != tail){
    u=dequeue();
    if(u.t>q){
      u.t=u.t-q;
      enqueue(u);
      elaps+=q;
    }
    else{
      printf("%s %d\n",u.name,u.t+elaps);
      elaps+=u.t;
    }
  }
  
  return 0;
}
void initialize(void){
  head=0;
  tail=0;
}
 
int isEmpty(void){
  if(head==tail)
    return TRUE;
  else
    return FALSE;
}
int isFull(void){
  if(head==(tail+1)%MAX)
    return TRUE;
  else
    return FALSE;
}
void enqueue(P x){
  if(isFull()){
    fprintf(stderr,"Overflow!!\n");
    exit(8);
  }
  else{
    Q[tail]=x;
    if(tail+1==LEN)
      tail=0;
    else
      tail++;
  }
}
P dequeue(void){
  P x;
  if(isEmpty()){
    fprintf(stderr,"Underflow!!\n");
    exit(8);
  }
  else{
    x=Q[head];
    if(head+1==LEN)
      head=0;
    else
      head++;
  }
  return x;
}