#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 100000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[MAX+1];
int head = 0, tail, n;

void enqueue(P x);
P dequeue(void);
/*int isEmpty(void);
  int isFull(void);*/

int main(){
  int elaps = 0, c, t = 0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  tail = i;

  for(i = 0;i < MAX; i++){
    if(Q[i].name == NULL) break;

    t = Q[i].t - q;

    if(t  > 0){
      Q[i].t = t;
      elaps += q;
      u = dequeue();
      enqueue(u);
    }
    else if(t <= 0){
      elaps += Q[i].t;
      u = dequeue();
      printf("ans:%s %d\n",u.name,elaps);
    } 
  } 
  return 0;
}

void enqueue(P x){
  /*if(isFull() == 1){
    exit(1);
    }else{*/
    Q[tail] = x;
    tail++;
    // }
}

P dequeue(){
  /*if(isEmpty() == 1){
    exit(1);
    }else{*/
    head++;
    return Q[head-1];
    //}
}

/*int isEmpty(){
  if(head == tail) return 1;
  else return 2;
}

int isFull(){
  if(head == ((tail+1)%MAX)) return 1;
  else return 2;
  }*/