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

#define NAME_SIZE 10
#define POOL_SIZE 100000

int main(void){
	char* name[POOL_SIZE];
	int time[POOL_SIZE];
	
	char n_tmp[NAME_SIZE]={};
	char n_tmp2[NAME_SIZE];
	int t_tmp;
	
	int n,q;
	
	scanf("%d",&n);
	scanf("%d",&q);
	
	scanf("%s",n_tmp);
	for(int i=0;i<n;i++){
		scanf("%d",&t_tmp);
		
		scanf("%s",n_tmp2);
		if(strcmp(n_tmp,n_tmp2)!=0){
			name[i]=(char*)malloc(sizeof(char)*strlen(n_tmp));
			strcpy(name[i],n_tmp);
			strcpy(n_tmp,n_tmp2);
			
			time[i]=t_tmp;
		}else{
			name[i]=(char*)malloc(sizeof(char)*strlen(n_tmp));
			strcpy(name[i],n_tmp);
			time[i]=t_tmp;
			break;
		}
	}
	int count=0;
	for(int total_time=0;total_time<1000000;){
		for(int i=0;i<n;i++){
			if(time[i]==0){
			}
			else if(time[i]<=q){
				count++;
				total_time+=time[i];
				time[i]=0;
				printf("%s %d\n",name[i],total_time);
			}
			else{
				total_time+=q;
				time[i]-=q;
			}
		}
		if(count>=n){
			break;
		}
	}
	return 0;
}
