#include<stdio.h>
#include<string.h>
#define MAX_LEN 100001

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

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

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

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

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

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