#include<stdio.h>

int main(){
  int i, n, q, total=0, remain, first = 0, tail = 0, time[100000], dis[100000];
  char name[100000][10];

  scanf("%d %d", &n, &q);
  if(n > 0 && n <= 100000 && q >= 1 && q <= 1000){
    for(i = 0; i < n; i++){
      scanf("%s %d", name[i], &time[i]);
      dis[i] = 1;
    }
    remain = n;
    tail = n - 1;
    
    while(remain != 0){
      time[first] = time[first] - q;
      if(time[first] < 0){
	total += (q + time[first]); 
	time[first] = 0;
      }else{
	total += q;
      }
      
      if(time[first] == 0){

	printf("%s %d\n", name[first], total);
        remain--;
	dis[tail] += dis[first];
	dis[first] = 0;
	first = tail;
	first += dis[tail];
	if(first >= n){
	    first = first - n;
	}
	
      }else{
	tail = first;
	first += dis[first];
      	if(first >= n) first = first - n;
      }
    }
  }
}

