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

#define MAX 150000

typedef struct Point{
  char data[100];
  int t;
} Point;

Point set[Max];
int heard;
int tail;
int k;

int main(){
  int el = 0;
  int c;
  int i;
  int l;
  Point u;

  scanf("%d %d",&k,&l);

  for(i = 0;i <= k;i++){
    scanf("%s",set[i].data);
    scanf("%d",&set[i].t);
  }
  head = 1;
  tail = k + 1;

  while(head != tail){
    u = notequal();
    c = minixm(l,u.t);
    u.t -= c;
    el += c;
    if(u.t > 0){
      equal(u);
    }
    else{
      printf("%s %d\n",u.name,el)
    }
  }
  return 0;
}


void equal(Point x){
  set[tail] = x;
  tail = (tail + 1) % MAX;
  return x;
}

Point notequal(){
  Point x = set[head];
  head = (head + 1) % MAX;
  return x;
}

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

