import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
 class Node{
	
	String name;
	int time;
	
	public Node(String name, int time) {
		this.name = name;
		this.time = time;
	}
}

public class Main{
	
	public static void main(String[] args) {
		Queue<Node> q = new LinkedList<>();
		Queue<String> result = new LinkedList<>();
		Scanner in = new Scanner(System.in);
		int processes = in.nextInt();
		int quantum = in.nextInt();
		
		for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		}
		
		int timer = 0;
		while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		}
			
	}
		
}
	 import java.util.LinkedList; LinkedList java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util class Node{
	
	String name;
	int time;
	
	public Node(String name, int time) {
		this.name = name;
		this.time = time;
	}
} Node String name; name int time; time public Node(String name, int time) {
		this.name = name;
		this.time = time;
	} Node {
		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{
	
	public static void main(String[] args) {
		Queue<Node> q = new LinkedList<>();
		Queue<String> result = new LinkedList<>();
		Scanner in = new Scanner(System.in);
		int processes = in.nextInt();
		int quantum = in.nextInt();
		
		for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		}
		
		int timer = 0;
		while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		}
			
	}
		
} Main public static void main(String[] args) {
		Queue<Node> q = new LinkedList<>();
		Queue<String> result = new LinkedList<>();
		Scanner in = new Scanner(System.in);
		int processes = in.nextInt();
		int quantum = in.nextInt();
		
		for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		}
		
		int timer = 0;
		while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		}
			
	} main {
		Queue<Node> q = new LinkedList<>();
		Queue<String> result = new LinkedList<>();
		Scanner in = new Scanner(System.in);
		int processes = in.nextInt();
		int quantum = in.nextInt();
		
		for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		}
		
		int timer = 0;
		while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		}
			
	} Queue<Node> q = new LinkedList<>(); q new LinkedList<>() Queue<String> result = new LinkedList<>(); result new LinkedList<>() Scanner in = new Scanner(System.in); in new Scanner(System.in) int processes = in.nextInt(); processes in.nextInt() in.nextInt in int quantum = in.nextInt(); quantum in.nextInt() in.nextInt in for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		} int i = 0; int i = 0; i 0 i < processes i processes i++ i++ i {
			q.add(new Node(in.next(), in.nextInt()));
		} {
			q.add(new Node(in.next(), in.nextInt()));
		} q.add(new Node(in.next(), in.nextInt())) q.add q new Node(in.next(), in.nextInt()) int timer = 0; timer 0 while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		} !(q.isEmpty()) (q.isEmpty()) q.isEmpty q {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		} Node task = q.remove(); task q.remove() q.remove q if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			} task.time <= quantum task.time task task.time quantum {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			} timer = timer + task.time timer timer + task.time timer task.time task task.time System.out.println(task.name + " " + Integer.toString(timer)) System.out.println System.out System System.out task.name + " " + Integer.toString(timer) task.name + " " + Integer.toString(timer) task.name task task.name " " Integer.toString(timer) Integer.toString Integer timer {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			} task.time = task.time - quantum task.time task task.time task.time - quantum task.time task task.time quantum q.add(task) q.add q task timer = timer + quantum timer timer + quantum timer quantum String[] args args public class Main{
	
	public static void main(String[] args) {
		Queue<Node> q = new LinkedList<>();
		Queue<String> result = new LinkedList<>();
		Scanner in = new Scanner(System.in);
		int processes = in.nextInt();
		int quantum = in.nextInt();
		
		for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		}
		
		int timer = 0;
		while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		}
			
	}
		
} public class Main{
	
	public static void main(String[] args) {
		Queue<Node> q = new LinkedList<>();
		Queue<String> result = new LinkedList<>();
		Scanner in = new Scanner(System.in);
		int processes = in.nextInt();
		int quantum = in.nextInt();
		
		for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		}
		
		int timer = 0;
		while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		}
			
	}
		
} Main
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
 class Node{
	
	String name;
	int time;
	
	public Node(String name, int time) {
		this.name = name;
		this.time = time;
	}
}

public class Main{
	
	public static void main(String[] args) {
		Queue<Node> q = new LinkedList<>();
		Queue<String> result = new LinkedList<>();
		Scanner in = new Scanner(System.in);
		int processes = in.nextInt();
		int quantum = in.nextInt();
		
		for(int i = 0; i < processes; i++) {
			q.add(new Node(in.next(), in.nextInt()));
		}
		
		int timer = 0;
		while(!(q.isEmpty())) {
			Node task = q.remove();
			if(task.time <= quantum) {
				timer = timer + task.time;
				System.out.println(task.name + " " + Integer.toString(timer));
			}
			else {
				task.time = task.time - quantum;
				q.add(task);
				timer = timer + quantum;
			}
			
			
		}
			
	}
		
}
	
