#include <stdio.h>
#define MAX 1000000
typedef struct pp{
  char s[100];
  int t;
}q;
q a[MAX];
int head,tail,n;
void en(q x){
  a[tail]=x;
  tail=(tail+1)%MAX;
}
q de(){
  q x=a[head];
  head=(head+1)%MAX;
  return x;
}
int min(int a,int b){
  return a<b ? a:b;
}

int main(){
  int n,i,c,laps=0,cc;
  q u;
  scanf("%d %d",&n,&c);
  for(i=1;i<=n;i++){
    scanf("%s",a[i].s);
    scanf("%d",&a[i].t);
  }
  head=1;
  tail=n+1;
  while(head!= tail){
    u=de();
    cc=min(c,u.t);
    u.t-=cc;
    laps+=cc;
    if(u.t>0){
      en(u);
    }
    else {
      printf("%s %d\n",u.s,laps);
    }
  }
  return 0;
}