#include<stdio.h>
#include<stdlib.h>

#define MAX 100005

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

int isempty(void);
int isfull(void);
void enqueue(Process);
Process dequeue(void);

Process List[MAX+1];
int head, tail, n;

int main(){
  int sum = 0, c;
  int i, q;
  Process box;
  scanf("%d %d", &n, &q);

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

  head = 0;
  tail = n;
  while(head != tail) {
    box = dequeue();
    if(q > box.time)
      c = box.time;
    else
      c = q;
    box.time -= c;
    sum += c;
    if(box.time > 0)
      enqueue(box);
    else
      printf("%s %d\n", box.name, sum);
  }
  
  return 0;
}

int isempty() {
  return head == tail;
}

int isfull() {
  return head == (tail+1)%MAX;
}

void enqueue(Process x){
  if(isfull()) {
    fprintf(stderr, "エラー（オーバーフロー）\n");
    exit(1);
  }
  List[tail] = x;
  if(tail+1 == MAX)
    tail = 0;
  else
    tail++;
}

Process dequeue(){
  Process x;
  if(isempty()) {
    fprintf(stderr, "エラー（アンダーフロー）\n");
    exit(1);
  }
  x = List[head];
  if(head+1 == MAX)
    head = 0;
  else
    head++;
  return x;
}