#include<stdio.h>

#define MAX 100000

struct Qtype{
	char name[11];
	int time;
};

struct Qtype Q[MAX];

int head,tail;

void initialize(int n){
	head = 0;
	tail = n;
}

int isEmpty(){
	if (head==tail){
		return 1;
	}else{
		return 0;
	}
}

int isFull(){
	if((tail+1)%MAX==head){
		return 1;
	}else{
		return 0;
	}
}

void enqueue(struct Qtype x){
	if(isFull()){
		printf("?????????????????????\n");
	}else{
		Q[tail]=x;
		if(tail+1==MAX){
			tail=0;
		}else{
			tail++;
		}
	}
}


struct Qtype dequeue(){
	struct Qtype x;
	if(isEmpty()){
		printf("??¢??????????????????\n");
		return (x);
	}else{
		x=Q[head];
		if(head+1==MAX){
			head=0;
		}else{
			head++;
		}
		return (x);
	}
}

int main(){
	int n, q, i, totaltime=0;
	struct Qtype x;

	scanf("%d %d",&n,&q);
	
	for(i=0; i<n; i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].time);
	}
	
	initialize(n);
	
	while(isEmpty() !=1){
		x=dequeue();
		if(x.time<=q){
			totaltime+=x.time;
			printf("%s,%d\n",x.name,totaltime);
		}else{
			x.time-=q;
			totaltime+=q;
			enqueue(x);
		}
	}
	return 0;
}