#include<stdio.h>
#include<string.h>

#define N 100000


typedef struct {
  int t;
  char name[10];
} data;

data dequeue(void);
int min(int x,int y);
void enqueue(data A);

data Q[N];
int head=1;
int tail=0;
int n;



int main(void){
  int t2;
  int k,q,i;
  data D;

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


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


  while(head != tail){
    D = dequeue();
    k = min(D.t,q); //qまたは必要な時間 u.tだけ処理を行う
    D.t -= k; //残りの必要時間を計算
    t2 += k; //経過時間を加算
    if(D.t > 0){
      enqueue(D);
    } else {
      printf("%s %d\n",D.name,t2);
    }
  }

  return 0;
}





data dequeue(){
  data A = Q[head];
  head = (head + 1)%N;
  
  return A;
}

void enqueue(data A){
  Q[tail] = A;
  tail = (tail + 1)%N;
}


int min(int x,int y){
  if(x < y){
    return x;
  } else {
    return y;
  }
}


