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

#define LEN 100005


typedef struct pp{
  char name[100];
  int p;
} P;


P Q[LEN];

int h,t,n;

void enqueue(P x)
{
  Q[t] = x;
  t = (t + 1) % LEN;
}

P dequeue()
{
  P x = Q[h];
  h = (h + 1) % LEN;
  return x;
}

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

int main(void)
{
  int e = 0, a;
  int i, b;
  P c;
  
  scanf("%d %d", &n, &b);

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

  while ( h != t ){
    c = dequeue();
    a = min(b, c.p);
    c.p -= a;
    e += a;
    if ( c.p > 0 ) enqueue(c);
    else {
      printf("%s %d\n", c.name, e);
    }
  }
  
  return 0;
}

