#include<stdio.h>
#include<string.h>
#define LEN 1000005

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

void enqueue(p );
p dequeue();
int min(int,int);
p q[LEN];

int head,tail,n;

int main(){
  int elaps = 0,h,i,r;
  p w;
  scanf("%d %d",&n,&r);
  for(i=1;i <= n;i++){
    scanf("%s %d",q[i].name,&q[i].u);
  }
  head=1;
  tail=n+1;
  while(head != tail){
    w = dequeue();
    h = min(r,w.u);
    w.u -= h;
    elaps += h;
    if(w.u > 0){
      enqueue(w);
    }
    else printf("%s %d\n",w.name,elaps);
  }
    return 0;
}
  void enqueue(p a){
    q[tail]=a;
    tail=(tail+1)%LEN;
  }
  p dequeue(){
    p x;
    x = q[head];
    head = (head+1)%LEN;
    return x;
  }
int min(int a,int b){return a < b ? a : b;}

