#include <stdio.h>
#define MAX 100005
typedef struct k{
  char name[10];
  int time;
}A;

void enqueue();
A dequeue();

int head=0,tail=0;
A Q[100000];
int main(){
  int i=0,n,q;
  int sum=0;
  A x;
  scanf("%d %d",&n,&q);
  for(i = 0; i < n; i ++){
    scanf("%s %d",Q[i].name,&Q[i].time);
  }
  head = 0;
  tail = n;
  
  while(head != tail){
    x = dequeue();
    if(x.time - q > 0){
      x.time -= q;
      sum += q;
      enqueue(x);
    }
    else if (x.time - q <= 0){
      sum += x.time;
      printf("%s %d\n",x.name,sum);
    }
  }
  return 0;
}
void enqueue(A x){
  Q[tail] = x;
  if(tail + 1 == MAX)tail = 0;
  else tail++;
}

A dequeue(){
  A x;
  x = Q[head];
  if(head + 1 == MAX) head = 0;
  else head++;
  return x;
}