#include<stdio.h>
#define N 100000
typedef struct rand {
  char c[10];
  int process;
}A;
int head=0,tail=0,n;
void enqueue(A);
A dequeue(void);
A r[N];
int main(){
  int i,q,sum=0,h;
  A s;
  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",r[i].c);
    scanf("%d",&r[i].process);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    s=dequeue();
    h=s.process;
    if((h-q)<=0){
      sum+=s.process;
      printf("%s %d\n",s.c,sum);
    }
    else if((h-q)>0){
      s.process-=q;
      enqueue(s);
      sum+=q;
    }
  }
  return 0;
}

void enqueue(A x){
  r[tail]=x;
  tail=(tail+1)%N;
}
A dequeue(){
  A x=r[head];
  head=(head+1)%N;
  return x;
}

