import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

// ALDS1_3_B
public class Main {
	public static void calc(Queue<Info> qu, int q) {
		Info info;
		int time = 0;
		while (!qu.isEmpty()) {
			info = qu.remove();
			if (info.time - q > 0) {
				info.time = info.time - q;
				qu.add(info);
				time += q;
			} else {
				time += info.time;
				System.out.println(info.name + " " + time);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue<Info> qu = new LinkedList<Info>();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			qu.add(new Info(sc.next(), sc.nextInt()));
		}
		calc(qu, q);
		sc.close();
	}
}

class Info {
	String name;
	int time;
	Info(String name, int time) {
		this.name = name;
		this.time = time;
	}
	Info() {}
}

/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