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

struct Data{
  char name[11];
  int t;
};

struct Data Q[1001];
int n, head=1, tail=1;

void enqueue(struct Data x){
  Q[tail] = x;
  if(tail == n)
    tail = 1;
  else
    tail++;
}

struct Data dequeue(){
  struct Data x;
  x = Q[head];

  if(head == n)
    head = 1;
  else head++;

  return x;
}

int main(){
  int i, q, count=0, time=0;
  struct Data a;

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

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

  while(count != n){
    a = dequeue();

    if(a.t <= q){
      time += a.t;
      printf("%s %d\n", a.name, time);
      count++;
    }

    else{
      time += q;
      a.t -= q;
      enqueue(a);
    }
  }

  return 0;
}