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

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

int main( void ) 
{
	struct queues ps[100001];
	int i,j;
	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 ) {
		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 );
			if( cur != start ) {
				for( j=cur; start<j; j-- ) {
					strcpy( ps[j].name, ps[j-1].name );
					ps[j].time=ps[j-1].time;
				}
			}
			start++;	
		} else {
			time+=q;
			ps[cur].time=res;
		}
		if( n==++cur ) { 
			cur=start;
		}		
	}
	
	
	return 0;
}