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

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

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail]=x;
    if(tail+1==n){
        tail=0;
    }
    else{
        tail++;
    }
}

P dequeue(){
    P x;
    x=Q[head];
    if(head+1==n){
        head=0;
    }
    else{
        head++;
    }
    return x;
}


int main(){
  int elaps = 0, c=0;
  int i, q, k=0,timec=0;
  P u,Q2[100000];
  scanf("%d %d", &n, &q);

  for ( i=0;i<n;i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  for(i=0;i<n;i++){
      elaps=Q[i].t-q;
      u=Q[i];
      dequeue();
      if(elaps>0){
          u.t=elaps;
          enqueue(u);
          timec+=q;
      }
      else{
          timec+=u.t;
          u.t=timec;
          Q2[c]=u;
          c++;
          if(c==n){
              break;
          }
      }
      if(i==n-1){
          i=-1;
      }
  }
  for(i=0;i<n;i++){
      printf("%s %d\n",Q2[i].name,Q2[i].t);
  }
  return 0;
}
