#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
  char c[100001][10],box[10];
  int time[100001];
  int i,n,q,top=0,tail=0,fcount=0,tcount=0,judgec=0;
  scanf("%d%d",&n,&q);
  
  for(i=0;fcount != n;i++){
    if(i < n){ 
      scanf("%s%d",c[i],&time[i]);
      tail++;
    }
    if(time[top]-q <= 0){
      tcount += time[top];
      time[top]=0;
      printf("%s %d\n",c[top],tcount);
      fcount++;
      if(top == n-1) top =0;
      else top++;
    }
      else{
	time[top]-=q;
	strcpy(c[tail],c[top]);
	time[tail]=time[top];
	tcount+=q;
	if(top == n-1) top = 0;
	else top++;