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

public class Main {
	
	private static class Process{
		public String n;
		public int t;
		
		public Process(String name, int time) {
			n = name;
			t = time;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String first = in.nextLine();
		String[] components = first.split(" ");
		int inputs = Integer.parseInt(components[0]);
		int quantum = Integer.parseInt(components[1]);
		int time = 0;
		
		//Creating the Queue of processes
		LinkedList<Process> q = new LinkedList<>();
		while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		}
		
		//Running
		while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		}
	}
} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main {
	
	private static class Process{
		public String n;
		public int t;
		
		public Process(String name, int time) {
			n = name;
			t = time;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String first = in.nextLine();
		String[] components = first.split(" ");
		int inputs = Integer.parseInt(components[0]);
		int quantum = Integer.parseInt(components[1]);
		int time = 0;
		
		//Creating the Queue of processes
		LinkedList<Process> q = new LinkedList<>();
		while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		}
		
		//Running
		while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String first = in.nextLine();
		String[] components = first.split(" ");
		int inputs = Integer.parseInt(components[0]);
		int quantum = Integer.parseInt(components[1]);
		int time = 0;
		
		//Creating the Queue of processes
		LinkedList<Process> q = new LinkedList<>();
		while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		}
		
		//Running
		while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		}
	} main {
		Scanner in = new Scanner(System.in);
		String first = in.nextLine();
		String[] components = first.split(" ");
		int inputs = Integer.parseInt(components[0]);
		int quantum = Integer.parseInt(components[1]);
		int time = 0;
		
		//Creating the Queue of processes
		LinkedList<Process> q = new LinkedList<>();
		while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		}
		
		//Running
		while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		}
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) String first = in.nextLine(); first in.nextLine() in.nextLine in String[] components = first.split(" "); components first.split(" ") first.split first " " int inputs = Integer.parseInt(components[0]); inputs Integer.parseInt(components[0]) Integer.parseInt Integer components[0] components 0 int quantum = Integer.parseInt(components[1]); quantum Integer.parseInt(components[1]) Integer.parseInt Integer components[1] components 1 int time = 0; time 0 LinkedList<Process> q = new LinkedList<>(); q new LinkedList<>() while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		} in.hasNextLine() in.hasNextLine in {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		} String i = in.nextLine(); i in.nextLine() in.nextLine in String[] c = i.split(" "); c i.split(" ") i.split i " " q.add(new Process(c[0], Integer.parseInt(c[1]))) q.add q new Process(c[0], Integer.parseInt(c[1])) while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		} !q.isEmpty() q.isEmpty() q.isEmpty q {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		} Process curr = q.poll(); curr q.poll() q.poll q if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			} curr.t <= quantum curr.t curr curr.t quantum {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} time += curr.t time curr.t curr curr.t System.out.println(curr.n + " " + time) System.out.println System.out System System.out curr.n + " " + time curr.n + " " + time curr.n curr curr.n " " time {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			} curr.t -= quantum curr.t curr curr.t quantum time += quantum time quantum q.add(curr) q.add q curr String[] args args private static class Process{
		public String n;
		public int t;
		
		public Process(String name, int time) {
			n = name;
			t = time;
		}
	} Process public String n; n public int t; t public Process(String name, int time) {
			n = name;
			t = time;
		} Process {
			n = name;
			t = time;
		} n = name n name t = time t time String name name int time time public class Main {
	
	private static class Process{
		public String n;
		public int t;
		
		public Process(String name, int time) {
			n = name;
			t = time;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String first = in.nextLine();
		String[] components = first.split(" ");
		int inputs = Integer.parseInt(components[0]);
		int quantum = Integer.parseInt(components[1]);
		int time = 0;
		
		//Creating the Queue of processes
		LinkedList<Process> q = new LinkedList<>();
		while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		}
		
		//Running
		while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		}
	}
} public class Main {
	
	private static class Process{
		public String n;
		public int t;
		
		public Process(String name, int time) {
			n = name;
			t = time;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String first = in.nextLine();
		String[] components = first.split(" ");
		int inputs = Integer.parseInt(components[0]);
		int quantum = Integer.parseInt(components[1]);
		int time = 0;
		
		//Creating the Queue of processes
		LinkedList<Process> q = new LinkedList<>();
		while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		}
		
		//Running
		while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		}
	}
} Main
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	private static class Process{
		public String n;
		public int t;
		
		public Process(String name, int time) {
			n = name;
			t = time;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String first = in.nextLine();
		String[] components = first.split(" ");
		int inputs = Integer.parseInt(components[0]);
		int quantum = Integer.parseInt(components[1]);
		int time = 0;
		
		//Creating the Queue of processes
		LinkedList<Process> q = new LinkedList<>();
		while (in.hasNextLine()) {
			String i = in.nextLine();
			String[] c = i.split(" ");
			q.add(new Process(c[0], Integer.parseInt(c[1])));
		}
		
		//Running
		while (!q.isEmpty()) {
			Process curr = q.poll();
			if (curr.t <= quantum) {
				time += curr.t;
				System.out.println(curr.n + " " + time);
			} else {
				curr.t -= quantum;
				time += quantum;
				q.add(curr);
			}
		}
	}
}
