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

/*?§???????*/
typedef struct pp{
  char name[100];
  int t;
}P;

/*????????????????????£?¨?*/
void enqueue(P);
P dequeue(void);


/*??°?????????????????°*/
P Q[LEN+1];
int head=1, tail, n;/*n?????????????????° */


int main(){
  int elaps = 0;
  int i, q; /*q?????????????????????*/
  P u;

  scanf("%d %d", &n, &q);

  tail = n+1;

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

  while(n!=0){
    u = dequeue(); /*?????????????´????????????????*/

    
    if(u.t>=q){
    u.t = u.t - q;
    elaps += q;
    }
    else{
        elaps += u.t;
        u.t = 0;
      }


    if(u.t==0){  /*????????????????????????????????¨???*/
        printf("%s %d\n",u.name,elaps);
        n -= 1;
    }
    else{
        enqueue(u);
    }
  }

  return 0;
}

/*??¢??°*/
void enqueue(P x){
  Q[tail] = x;
  tail++;
}

P dequeue(){
  head++;
  return Q[head-1];
}