#include <stdio.h>
#include <string.h>
#define MAX 100005

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

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

P Q[MAX];
int head, tail, n;

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

  for(i=1; i<=n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min(s, u.time);
    u.time -= c;
    elaps += c;
    if(u.time>0){
      enqueue(u);
    }
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}

void enqueue(P x){
  Q[tail] = x;
  if(tail+1 == MAX){
    tail = 0;
  }
  else{
    tail++;
  }
}

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

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