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

public class Main {

	public static void main(String[] args) {
		Queue<String[]> tasks = new LinkedList<String[]>(), finished = new LinkedList<String[]>();
		Scanner sc = new Scanner(System.in);
		String[] l1 = sc.nextLine().split(" ");
		int quantum = Integer.valueOf(l1[1]), eclipsedTime=0;
		for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		}
		while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		}
		for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		}
	}

}
 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Queue<String[]> tasks = new LinkedList<String[]>(), finished = new LinkedList<String[]>();
		Scanner sc = new Scanner(System.in);
		String[] l1 = sc.nextLine().split(" ");
		int quantum = Integer.valueOf(l1[1]), eclipsedTime=0;
		for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		}
		while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		}
		for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		}
	}

} Main public static void main(String[] args) {
		Queue<String[]> tasks = new LinkedList<String[]>(), finished = new LinkedList<String[]>();
		Scanner sc = new Scanner(System.in);
		String[] l1 = sc.nextLine().split(" ");
		int quantum = Integer.valueOf(l1[1]), eclipsedTime=0;
		for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		}
		while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		}
		for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		}
	} main {
		Queue<String[]> tasks = new LinkedList<String[]>(), finished = new LinkedList<String[]>();
		Scanner sc = new Scanner(System.in);
		String[] l1 = sc.nextLine().split(" ");
		int quantum = Integer.valueOf(l1[1]), eclipsedTime=0;
		for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		}
		while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		}
		for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		}
	} Queue<String[]> tasks = new LinkedList<String[]>() tasks new LinkedList<String[]>() finished = new LinkedList<String[]>(); finished new LinkedList<String[]>() Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] l1 = sc.nextLine().split(" "); l1 sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int quantum = Integer.valueOf(l1[1]) quantum Integer.valueOf(l1[1]) Integer.valueOf Integer l1[1] l1 1 eclipsedTime=0; eclipsedTime 0 for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		} int i = 0; int i = 0; i 0 i < Integer.valueOf(l1[0]) i Integer.valueOf(l1[0]) Integer.valueOf Integer l1[0] l1 0 i++ i++ i {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		} {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		} String[] line = sc.nextLine().split(" "); line sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " tasks.add(new String[]{line[0],line[1]}) tasks.add tasks new String[]{line[0],line[1]} while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		} tasks.size()>0 tasks.size() tasks.size tasks 0 {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		} String[] currentTask = tasks.poll(); currentTask tasks.poll() tasks.poll tasks if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			} Integer.valueOf(currentTask[1])<=quantum Integer.valueOf(currentTask[1]) Integer.valueOf Integer currentTask[1] currentTask 1 quantum { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			} int partialTime = Integer.valueOf(currentTask[1]); partialTime Integer.valueOf(currentTask[1]) Integer.valueOf Integer currentTask[1] currentTask 1 finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)}) finished.add finished new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)} eclipsedTime+=partialTime eclipsedTime partialTime {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			} currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum) currentTask[1] currentTask 1 Integer.toString(Integer.valueOf(currentTask[1])-quantum) Integer.toString Integer Integer.valueOf(currentTask[1])-quantum Integer.valueOf(currentTask[1]) Integer.valueOf Integer currentTask[1] currentTask 1 quantum tasks.add(currentTask) tasks.add tasks currentTask eclipsedTime+=quantum eclipsedTime quantum for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		} String[] task finished {
			System.out.println(task[0]+" "+task[1]);
		} {
			System.out.println(task[0]+" "+task[1]);
		} System.out.println(task[0]+" "+task[1]) System.out.println System.out System System.out task[0]+" "+task[1] task[0]+" "+task[1] task[0] task 0 " " task[1] task 1 String[] args args public class Main {

	public static void main(String[] args) {
		Queue<String[]> tasks = new LinkedList<String[]>(), finished = new LinkedList<String[]>();
		Scanner sc = new Scanner(System.in);
		String[] l1 = sc.nextLine().split(" ");
		int quantum = Integer.valueOf(l1[1]), eclipsedTime=0;
		for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		}
		while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		}
		for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		}
	}

} public class Main {

	public static void main(String[] args) {
		Queue<String[]> tasks = new LinkedList<String[]>(), finished = new LinkedList<String[]>();
		Scanner sc = new Scanner(System.in);
		String[] l1 = sc.nextLine().split(" ");
		int quantum = Integer.valueOf(l1[1]), eclipsedTime=0;
		for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		}
		while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		}
		for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		}
	}

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

public class Main {

	public static void main(String[] args) {
		Queue<String[]> tasks = new LinkedList<String[]>(), finished = new LinkedList<String[]>();
		Scanner sc = new Scanner(System.in);
		String[] l1 = sc.nextLine().split(" ");
		int quantum = Integer.valueOf(l1[1]), eclipsedTime=0;
		for (int i = 0; i < Integer.valueOf(l1[0]); i++) {
			String[] line = sc.nextLine().split(" ");
			tasks.add(new String[]{line[0],line[1]});
		}
		while(tasks.size()>0) {
			String[] currentTask = tasks.poll();
			if(Integer.valueOf(currentTask[1])<=quantum) { 
				int partialTime = Integer.valueOf(currentTask[1]);
				finished.add(new String[] {currentTask[0],Integer.toString(partialTime+eclipsedTime)});
				eclipsedTime+=partialTime;
			}
			else {
				currentTask[1]=Integer.toString(Integer.valueOf(currentTask[1])-quantum);
				tasks.add(currentTask);
				eclipsedTime+=quantum;
			}

		}
		for(String[] task: finished) {
			System.out.println(task[0]+" "+task[1]);
		}
	}

}

