#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct q{
  char name[100];
  int t;
}QU;

QU Q[LEN+1];
int head, tail, n;

int main(){
  int elaps = 0, c;
  int i, q;
  QU u;
  scanf("%d %d", &n, &q);
  head = 1;
  tail = n+1;
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  while(head != tail) {
    u = Q[head];
    head = (head+1) % LEN;
    if(q > u.t) c = u.t;
    else c = q;
    u.t -= c;
    elaps += c;
    if(u.t > 0) {
      Q[tail] = u;
      tail = (tail+1) % LEN;
    }
    else {
      printf("%s %d\n", u.name, elaps);
    }
  }



  return 0;
}

