#include<stdio.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);
P dequeue(void);
 
 
P Q[MAX+1];
int head,tail,n;

int main()
{
  int c,elaps = 0;
  int i,q;
  P u;

  scanf("%d%d",&n,&q);

  initialize();

  tail = n;

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

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

void initialize()
{
  head = tail = 0;
}
 
int isEmpty()
{
  return head == tail;
}
 
int isFull()
{
  return head == ( tail + 1 ) % MAX;
}
 
void enqueue(P x)
{
  if(isFull()) return;

  Q[tail] = x;

  if(tail + 1 == MAX) tail = 0;
  else tail++;
}
 
P dequeue()
{
  P x;

  if(isEmpty()) return;

  x = Q[head];

  if(head + 1 == MAX) head = 0;
  else head++;

  return x;
}
 