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

#define QLEN 60000

typedef struct {
  char name[11];
  int time;
} process;

int main()
{
  int d, i, n, q, sp, head, time;
  char buf[32], *p;
  fgets(buf, 32, stdin);
  for (p=buf, n=0; *p!=' '; p++)   n = n * 10 + *p - '0';
  for (p++,q=0; *p!='\n'; p++)   q = q * 10 + *p - '0';
  process *proc = (process*)malloc(sizeof(process)*QLEN);
  for (sp=0; sp<n; sp++) {
    fgets(buf, 32, stdin);
    for (p=buf, i=0; *p!=' '; p++,i++)  proc[sp].name[i] = *p;
    proc[sp].name[i]=0;
    for (p++,proc[sp].time=0; *p!='\n'; p++)
      proc[sp].time = proc[sp].time * 10 + *p - '0';
  }
  time = head = 0;
  buf[31] = 0;
  buf[30] = '\n';
  while ((sp-head+QLEN)%QLEN>0) {
    process p = proc[head++%QLEN];
    if (p.time-q<=0) {
      time += p.time;
      fputs(p.name, stdout);
      d = time;
      for (i=30; d>0; buf[--i]='0'+d%10,d/=10);
      buf[--i] = ' ';
      fputs(buf+i, stdout);
    } else {
      p.time -= q;
      time += q;
      proc[sp++%QLEN] = p;
    }
  }

  return 0;
}

