#include <stdio.h>
#include <string.h>
#define len 100000

typedef struct pc{
  char name[11];
  int t;
}p;

p Queue[len];
int head,tail,n;

void enqueue(p);
p dequeue();

int min(int,int);

int main(){
  int i,q;
  p u;
  int elaps = 0,c;

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

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

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

  return 0;
}

void enqueue(p x)
{
  Queue[tail] = x;
  tail = (tail + 1) % len;
}

p dequeue()
{
  p x = Queue[head];
  head = (head + 1) % len;
  return x;
}

int min(int a,int b)
{
  return a < b ? a : b;
}
