import std.stdio;
import std.string;
import std.conv;

struct Queue{
	int pTime;
	char[256] name;
	int endTime;
};

void main(){
	int n,q;
	Queue[] queue;
	int cntTime = 0;
	int cnt = 0;
	int cntEnd = 0;
	int[] end;
	char[] str;
	scanf( "%d %d",&n,&q );
	queue = new Queue[n];
	end   = new int[n];
	foreach( i;0 .. n ){
		scanf( "%s %d",&queue[i].name[0],&queue[i].pTime );
		queue[i].name = ( queue[i].name ).chomp().dup();
	}
	while( cntEnd < n ){
		if( queue[cnt].pTime == 0 ){
			cnt++;
		}else if( queue[cnt].pTime <= q ){
			cntTime += queue[cnt].pTime;
			queue[cnt].pTime = 0;
			queue[cnt].endTime = cntTime;
			end[cntEnd++] = cnt++;
		}else if( queue[cnt].pTime > q ){
			queue[cnt].pTime -= q;
			cntTime += q;
			cnt++;
		}
		if( cnt >= n ) cnt = 0;
	}
	foreach( i;0 .. n ){
		for( int j = 0;queue[ end[i]].name[j] != 0;j++ ){
			write( queue[ end[i]].name[j] );
		}
		writeln( " ",queue[ end[i]].endTime );
	}
}