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

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

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

P pro[100000];
int head=0,tail=0;

int main()
{
  int n,q,i;

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

  for(i=0;i<n;i++){
    scanf("%s%d",pro[tail].name,&pro[tail].qms);
    tail = (tail+1)%100000;
  }

  Calc(q,n);

  return 0;
}

void Calc(int q,int n)
{
  P a;
  int Q=0;
  
  while(1){
    a = dequeue();
    if(a.qms > q){
      a.qms = a.qms-q;
      enqueue(a);
      Q += q;
    }
    else if(a.qms <= q){
      Q += a.qms;
      printf("%s %d\n",a.name,Q);
      n--;
      if(n==0) break;
    }
  }
}

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

P dequeue(void)
{
  P d;

  d = pro[head];
  head = (head+1)%100000;

  return d;
}


  
  
    
    
    
    
    
  

