#include<stdio.h>
#define N 100001

typedef struct
{
  char name[15];
  int time;
}job;

job J[N+1]={};
int head;
int tail;

int isEmpty();
int isFull();
void enqueue(job);
job dequeue();
int min(int, int);

int main()
{
  int n,q;
  int i;
  scanf("%d%d",&n,&q);
  
  for(i=0;i < n;i++){
    scanf("%s%d",J[i].name, &J[i].time);
  }
  head = 0;
  tail = n;

  job process;
  int jobtime = 0;
  int t;
  
  while( !isEmpty() ){
    process = dequeue(n);
    t = min(process.time, q);
    process.time -= t;
    jobtime += t;
    
    if(process.time > 0){
      enqueue(process);
    }
    else{
      printf("%s %d\n", process.name, jobtime);
    }
  }
  return 0;
}

void enqueue(job j)
{
  J[tail] = j;
  tail = (++tail)%N;
}

job dequeue()
{
  job j = J[head];
  head = (++head)%N;
  return j;
}

int isFull()
{
  return head == (tail+1)%N;
}

int isEmpty(){
  return head == tail;
}

int min(int a, int b)
{
  if(a < b) return a;
  else return b;
}


