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

typedef struct pro{
  char name[100];
  int time;
}p;


void enqueue(p);
p dequeue(void);
int min(int, int);

int head, tail;
p proc[N];

int main(){
  int i, n, q, c, total=0;
  p data;

  scanf("%d%d", &n, &q);
  for(i=1;i<=n;i++){
    scanf("%s%d",proc[i].name, &proc[i].time);
  }


  head = 1;
  tail = n+1;

  while(head != tail){
    data = dequeue();
    c = min(q, data.time);
    data.time -= c;
    total += c;

    if(data.time > 0){
      enqueue(data);
    }else{
      printf("%s %d\n", data.name, total);
    }
  }

  return 0;
}




void enqueue(p n){
  proc[tail] = n;
  tail = (tail+1)%N;
}


p dequeue(){
  p n = proc[head];
  head = (head+1)%N;
  return n;
}

int min(int a, int b){
  if(a>=b){
    return b;
  }else{
    return a;
  }
}



