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

struct proc {
  char name[10 + 1];
  int time;
  int fin;

  struct proc *fp;
  struct proc *bp;
};

struct proc list;
struct proc finished;

void add_last(struct proc *h, struct proc *p);
void remove_first(struct proc *h, struct proc *p);

int main(int argc, char *argv[])
{
  int n, q, i;
  int t = 0;
  struct proc *p, *ip;
  struct proc *exec;
  char tmpname[10 + 1];
  int tmptime;

  list.fp = &list;
  list.bp = &list;
  finished.fp = &finished;
  finished.bp = &finished;

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

  p = (struct proc *)malloc(sizeof(struct proc) * n);

  for (i = 0; i < n; i++) {
    scanf("%s", &tmpname[0]);
    scanf("%d", &tmptime);
    strcpy(p[i].name, tmpname);
    p[i].time = tmptime;
    add_last(&list, &p[i]);
  }

  while (list.fp != &list) {
    exec = list.fp;
    remove_first(&list, exec);
    if (exec->time > q) {
      exec->time -= q;
      t += q;
      add_last(&list, exec);
    } else {
      t += exec->time;
      exec->fin = t;
      add_last(&finished, exec);
    }
  }

  for (ip = finished.fp; ip != &finished; ip = ip->fp) {
    printf("%s %d\n", ip->name, ip->fin);
  }

  free(p);
  
  return 0;
}

void add_last(struct proc *h, struct proc *p)
{
  p->fp = h;
  p->bp = h->bp;
  h->bp = p;
  p->bp->fp = p;
}

void remove_first(struct proc *h, struct proc *p)
{
  h->fp = p->fp;
  p->fp->bp = h;
  p->fp = NULL;
  p->bp = NULL;
}