import java.util.*;

public class Main{	

public static void main(String[] args) {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
}
} import java.util.*; util.* java public class Main{	

public static void main(String[] args) {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
}
} Main public static void main(String[] args) {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
} main {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
} Queue<String> name = new LinkedList<String>(); name new LinkedList<String>() Queue<Integer> time = new LinkedList<Integer>(); time new LinkedList<Integer>() Scanner in = new Scanner(System.in); in new Scanner(System.in) int elems = in.nextInt(); elems in.nextInt() in.nextInt in int timer = in.nextInt(); timer in.nextInt() in.nextInt in int timePassed = 0; timePassed 0 in.nextLine() in.nextLine in String eName = ""; eName "" int eTime = 0; eTime 0 for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	} int i = 0; int i = 0; i 0 i < elems i elems i++ i++ i {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	} {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	} eName = in.next() eName in.next() in.next in name.add(eName) name.add name eName eTime = in.nextInt() eTime in.nextInt() in.nextInt in time.add(eTime) time.add time eTime while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	} !name.isEmpty() name.isEmpty() name.isEmpty name {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	} String str = name.poll(); str name.poll() name.poll name int remainingTime = time.poll(); remainingTime time.poll() time.poll time if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		} remainingTime <= timer remainingTime timer {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		} timePassed += remainingTime timePassed remainingTime System.out.println(str + " " + timePassed) System.out.println System.out System System.out str + " " + timePassed str + " " + timePassed str " " timePassed {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		} remainingTime -= timer remainingTime timer name.add(str) name.add name str time.add(remainingTime) time.add time remainingTime timePassed += timer timePassed timer String[] args args public class Main{	

public static void main(String[] args) {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
}
} public class Main{	

public static void main(String[] args) {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
}
} Main
import java.util.*;

public class Main{	

public static void main(String[] args) {
	Queue<String> name = new LinkedList<String>();
	Queue<Integer> time = new LinkedList<Integer>();
	
	Scanner in = new Scanner(System.in);
	
	int elems = in.nextInt();
	int timer = in.nextInt();
	int timePassed = 0;
	in.nextLine();
	
	String eName = "";
	int eTime = 0;
	
	for (int i = 0; i < elems; i++) {
		eName = in.next();
		name.add(eName);
		eTime = in.nextInt();
		time.add(eTime);
	}
	
	while(!name.isEmpty()) {
		String str = name.poll();
		int remainingTime = time.poll();
		if (remainingTime <= timer) {
			timePassed += remainingTime;
			System.out.println(str + " " + timePassed);
		}
		else {
			remainingTime -= timer;
			name.add(str);
			time.add(remainingTime);
			timePassed += timer;
		}
	}
}
}
