import java.util.Scanner;

public class Main {
	public static int head1 = 0;
	public static int head2 = 0;
	public static int tail = 0;
	public static String[] queue1 = new String[1000000];
	public static int[] queue2 = new int[1000000];
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
		
		for (int i = 0; i < n; i++) {
			String a = stdIn.next();
			int b = stdIn.nextInt();
			enqueue(a, b);
		}
		
		int time = 0;
		while (head1 != tail) {
			String a = strDequeue();
			int b = intDequeue();
			if (b <= q) {
				time += b;
				System.out.println(a +" "+ time);
			}
			else {
				time += q;
				b -= q;
				enqueue(a, b);
			}
		}
	}
	
	public static void enqueue(String x, int y) {
		queue1[tail] = x;
		queue2[tail] = y;
		tail++;
	}
	
	public static String strDequeue() {
		return queue1[head1++];
	}
	
	public static int intDequeue() {
		return queue2[head2++];
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz