#include<stdio.h>
#define L 100
#define MAX 1000000
typedef struct pp{
	char name[L];
	int time;
}p;
void enqueue(p);
p dequeue();
int calct(int,int);
int n,q,i,head=1,tail=0,max,ctime,stime;
p Q[MAX];
int main(){
  scanf("%d%d",&n,&q);
  tail = n+1;
  max = n;
  p nowq;
  for(i=1;i<=n;i++){
  	scanf("%s",Q[i].name);
  	scanf("%d",&Q[i].time);
  }
  while(head != tail){
  	nowq = dequeue();
  	ctime = calct(q,nowq.time);
  	stime += ctime;
  	nowq.time -= ctime;
  	if(nowq.time > 0)enqueue(nowq);
  	else printf("%s %d\n",nowq.name,stime);
  }
  return 0;
}
void enqueue(p now){
	Q[tail] = now;
	tail=(tail+1)%MAX;
}
p dequeue(){
	p temp=Q[head];
	head=(head+1)%MAX;
    return temp;
}
int calct(int q,int time){
	if(q < time) return q;
	else if(q > time)return time;
}
