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

#define MAX 100000

typedef struct{
	char name[10];
	int time;
}process;

void initialize();
int isEmpty();
int isFull();
void enqueue( process x );
process dequeue();
int min( int x , int y );

int head , tail;
process Q[MAX];

int main( void ){
	
	int n , q;
	int i;
	int c;
	int total = 0;
	
	process x;
	
	scanf( "%d %d" , &n , &q );
	
	for( i = 1; i <= n; i++ ){
		scanf( "%s %d" , Q[i].name , &Q[i].time );
	}
	
	initialize();
	head = 1;
	tail = n + 1;
	
	while( head != tail ){
		x = dequeue();
		c = min( q , x.time );
		x.time -= c;
		total += c;
		if( x.time > 0 ){
			enqueue(x);
		}else{
			printf( "%s %d\n" , x.name , total );
		}
	}
}

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

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

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

void enqueue( process x ){
	
	if( isFull() == 1 ){
		fprintf( stderr , "エラー(オーバーフロー)" );
	}else{
		Q[tail] = x;
		if ( tail + 1 == MAX ){
			tail = 0;
		}else{
			tail++;
		}
	}
	
}

process dequeue(){
	
	process x;
	
	if( isEmpty() == 1 ){
		fprintf( stderr , "エラー(アンダーフロー)" );
		exit(0);
	}else{
		x = Q[head];
		if( head + 1 == MAX ){
			head = 0;
		}else{
			head++;
		}
		return x;
	}
	
}
	
int min( int x , int y ){
	
	if( x < y ){
		return x; 
	}else{
		return y;
	}
	
}

