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

class Task {
	public String name;
	public int time;
	
	Task(String name, int time) {
		this.name = name;
		this.time = time;
	}
}
public class Main{
	static LinkedList<Task> queue = new LinkedList<>();
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sumTime = 0;
		
		int taskNum = sc.nextInt();
		int levelTime = sc.nextInt();
		
		if(taskNum < 1 || taskNum > 100000)
			return;
		if(levelTime < 1 || levelTime > 1000)
			return;
		
		for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		}
		
		
		while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		}
	}
} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util class Task {
	public String name;
	public int time;
	
	Task(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Task public String name; name public int time; time Task(String name, int time) {
		this.name = name;
		this.time = time;
	} Task {
		this.name = name;
		this.time = time;
	} this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public class Main{
	static LinkedList<Task> queue = new LinkedList<>();
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sumTime = 0;
		
		int taskNum = sc.nextInt();
		int levelTime = sc.nextInt();
		
		if(taskNum < 1 || taskNum > 100000)
			return;
		if(levelTime < 1 || levelTime > 1000)
			return;
		
		for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		}
		
		
		while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		}
	}
} Main static LinkedList<Task> queue = new LinkedList<>(); queue new LinkedList<>() public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sumTime = 0;
		
		int taskNum = sc.nextInt();
		int levelTime = sc.nextInt();
		
		if(taskNum < 1 || taskNum > 100000)
			return;
		if(levelTime < 1 || levelTime > 1000)
			return;
		
		for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		}
		
		
		while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int sumTime = 0;
		
		int taskNum = sc.nextInt();
		int levelTime = sc.nextInt();
		
		if(taskNum < 1 || taskNum > 100000)
			return;
		if(levelTime < 1 || levelTime > 1000)
			return;
		
		for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		}
		
		
		while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int sumTime = 0; sumTime 0 int taskNum = sc.nextInt(); taskNum sc.nextInt() sc.nextInt sc int levelTime = sc.nextInt(); levelTime sc.nextInt() sc.nextInt sc if(taskNum < 1 || taskNum > 100000)
			return; taskNum < 1 || taskNum > 100000 taskNum < 1 taskNum 1 taskNum > 100000 taskNum 100000 return; if(levelTime < 1 || levelTime > 1000)
			return; levelTime < 1 || levelTime > 1000 levelTime < 1 levelTime 1 levelTime > 1000 levelTime 1000 return; for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		} int i = 0; int i = 0; i 0 i < taskNum i taskNum i++ i++ i {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		} {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		} queue.offer(new Task(sc.next(), sc.nextInt())) queue.offer queue new Task(sc.next(), sc.nextInt()) while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		} Task task = queue.poll(); task queue.poll() queue.poll queue if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			} task.time <= levelTime task.time task task.time levelTime {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} sumTime += task.time sumTime task.time task task.time System.out.println(task.name + " " + sumTime) System.out.println System.out System System.out task.name + " " + sumTime task.name + " " + sumTime task.name task task.name " " sumTime {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			} task.time -= levelTime task.time task task.time levelTime sumTime += levelTime sumTime levelTime queue.offer(task) queue.offer queue task String[] args args public class Main{
	static LinkedList<Task> queue = new LinkedList<>();
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sumTime = 0;
		
		int taskNum = sc.nextInt();
		int levelTime = sc.nextInt();
		
		if(taskNum < 1 || taskNum > 100000)
			return;
		if(levelTime < 1 || levelTime > 1000)
			return;
		
		for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		}
		
		
		while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		}
	}
} public class Main{
	static LinkedList<Task> queue = new LinkedList<>();
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sumTime = 0;
		
		int taskNum = sc.nextInt();
		int levelTime = sc.nextInt();
		
		if(taskNum < 1 || taskNum > 100000)
			return;
		if(levelTime < 1 || levelTime > 1000)
			return;
		
		for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		}
		
		
		while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		}
	}
} Main
import java.util.LinkedList;
import java.util.Scanner;

class Task {
	public String name;
	public int time;
	
	Task(String name, int time) {
		this.name = name;
		this.time = time;
	}
}
public class Main{
	static LinkedList<Task> queue = new LinkedList<>();
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sumTime = 0;
		
		int taskNum = sc.nextInt();
		int levelTime = sc.nextInt();
		
		if(taskNum < 1 || taskNum > 100000)
			return;
		if(levelTime < 1 || levelTime > 1000)
			return;
		
		for (int i = 0; i < taskNum; i++) {
			 queue.offer(new Task(sc.next(), sc.nextInt()));
		}
		
		
		while(!queue.isEmpty()) {
			Task task = queue.poll();
			
			if(task.time <= levelTime) {
				sumTime += task.time;
				System.out.println(task.name + " " + sumTime);
			} else {
				task.time -= levelTime;
				sumTime += levelTime;
				queue.offer(task);
			}
		}
	}
}