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

#include<math.h>
#define QUEUE_SIZE 7
typedef struct{
  char name[10];
  int ms;
  
}P;
void Calc (int ,int);
void enque(P);
P deque(void);
P pro[100000];
int head =0,tail=0;
int main(){
  int d,s,i;
  scanf("%d %d",&d,&s);
  for(i=0;i<d;i++){
    scanf("%s%d",pro[tail].name,&pro[tail].ms);
    tail=(tail+1)%100000;
  }
    Calc(s,d);
    return 0;
}
  void Calc(int q,int n)
  {int Q=0;
    P a;
    while (1){
      a=deque();
      if(a.ms >q){
	a.ms=a.ms-q;
	enque(a);
	Q+=q;}
      else if(a.ms<=q){
	Q+=a.ms;
	printf("%s %d\n",a.name,Q);
	n--;
	if(n==0)break;
      }
    }
  }
  

  void enque(P k){
    pro[tail]=k;
    tail=(tail+1)%100000;
  }
  P deque(void){
    P k;
    k=pro[head];
    head=(head+1) %100000;
    return k;
  }

