  char name[100];
  int t;
}P;
 
P Q[LEN+1];
int head, tail, n;
 
void enqueue(P x){
  Q[tail]=x;
  if(tail + 1 == MAX)
    tail=0;
  else
    tail++;
}
 
P dequeue(void){
  P x;
  x=Q[head];
  if(head+1 == MAX)
    head=0;
  else head++;
  return x;
}
 
 
int main(){
  int elaps = 0, c;
  int i, q;
  P p;
  scanf("%d %d", &n, &q);
 
  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
    head = 0;
    tail = n;

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