#include <stdio.h>
#include <string.h>
#define LEN 100005
typedef struct pp{
  char name[100];
  int t;
}T_p;
T_p Q[LEN + 1];
int head, tail, n;
void enqueue(T_p);
T_p dequeue();
int main(){
  int elaps = 0, c;
  int i, q;
  T_p u;
  scanf("%d %d", &n, &q);
  for(i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1, tail = n + 1;
  int sum = 0;
  int cnt = 0;
  while(head != tail){
    if(Q[head].t <= q){
      sum += Q[head].t;
      printf("%s %d\n", Q[head].name, sum);
      dequeue();
    }
    else{
      sum += q;
      Q[head].t -= q;
      enqueue(dequeue());
    }
    cnt++;
    if(!(cnt % 10)){
      char c;
      scanf("%c", &c);
    }
  }
  return 0;
}

void enqueue(T_p x){
  Q[tail] = x;
  tail++;
  if(tail > LEN)
    tail = 0;
}

T_p dequeue(){
  T_p tmp = Q[head];
  head++;
  if(head > LEN)
    head = 0;
  return tmp;
}