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

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

int main( void ) 
{
	struct queues ps[100001];
	int i;
	int n,q;
	int start,cur;
	int time,res;	
	
	scanf( "%d%d", &n, &q );
	for( i=0; i<n; i++ ) {
		scanf( "%s%d", ps[i].name, &ps[i].time );
	}
	
	res=time=cur=start=0;
	while( start<n ) {
		if( '\0' != ps[cur].name[0] ) {
			res=ps[cur].time-q;
			if( res <= 0 ) {
				time+=ps[cur].time;
				ps[cur].time=time;
				printf( "%s %d\n", ps[cur].name, ps[cur].time );
				ps[cur].name[0]='\0';
				start++;	
			} else {
				time+=q;
				ps[cur].time=res;
			}
		}
		if( n==++cur ) { 
			cur=0;
		}
		
	}
	
	
	return 0;
}