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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	}
}

class Process {
	private String name;
	private int cpuTime;
	public Process(String name, int cpuTime) {
		this.name = name;
		this.cpuTime = cpuTime;
	}
	public String getName() {
		return name;
	}
	public int getCpuTime() {
		return cpuTime;
	}
	public void setCpuTime(int cpuTime) {
		this.cpuTime = cpuTime;
	}
	public boolean isFinished() {
		return this.cpuTime <= 0;
	}
}

class Queue {
	private LinkedList<Process> queue;
	public Queue() {
		queue = new LinkedList<Process>();
	}
	public void enqueue(Process p) {
		queue.addLast(p);
	}
	public Process dequeue() {
		Process ret = queue.getFirst();
		queue.removeFirst();
		return ret;
	}
	public boolean isEmpty() {
		return queue.size() <= 0;
	}
} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue queue = new Queue(); queue new Queue() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q = sc.nextInt(); q sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		} {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		} String name = sc.next(); name sc.next() sc.next sc int cpuTime = sc.nextInt(); cpuTime sc.nextInt() sc.nextInt sc Process p = new Process(name, cpuTime); p new Process(name, cpuTime) queue.enqueue(p) queue.enqueue queue p sc.close() sc.close sc int totalTime = 0; totalTime 0 while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		} Process p = queue.dequeue(); p queue.dequeue() queue.dequeue queue int time = Math.min(p.getCpuTime(), q); time Math.min(p.getCpuTime(), q) Math.min Math p.getCpuTime() p.getCpuTime p q p.setCpuTime(p.getCpuTime() - time) p.setCpuTime p p.getCpuTime() - time p.getCpuTime() p.getCpuTime p time totalTime += time totalTime time if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			} p.isFinished() p.isFinished p {
				System.out.println(p.getName() + " " + totalTime);
			} System.out.println(p.getName() + " " + totalTime) System.out.println System.out System System.out p.getName() + " " + totalTime p.getName() + " " + totalTime p.getName() p.getName p " " totalTime {
				queue.enqueue(p);
			} queue.enqueue(p) queue.enqueue queue p String[] args args class Process {
	private String name;
	private int cpuTime;
	public Process(String name, int cpuTime) {
		this.name = name;
		this.cpuTime = cpuTime;
	}
	public String getName() {
		return name;
	}
	public int getCpuTime() {
		return cpuTime;
	}
	public void setCpuTime(int cpuTime) {
		this.cpuTime = cpuTime;
	}
	public boolean isFinished() {
		return this.cpuTime <= 0;
	}
} Process private String name; name private int cpuTime; cpuTime public Process(String name, int cpuTime) {
		this.name = name;
		this.cpuTime = cpuTime;
	} Process {
		this.name = name;
		this.cpuTime = cpuTime;
	} this.name = name this.name this this.name name this.cpuTime = cpuTime this.cpuTime this this.cpuTime cpuTime String name name int cpuTime cpuTime public String getName() {
		return name;
	} getName {
		return name;
	} return name; name public int getCpuTime() {
		return cpuTime;
	} getCpuTime {
		return cpuTime;
	} return cpuTime; cpuTime public void setCpuTime(int cpuTime) {
		this.cpuTime = cpuTime;
	} setCpuTime {
		this.cpuTime = cpuTime;
	} this.cpuTime = cpuTime this.cpuTime this this.cpuTime cpuTime int cpuTime cpuTime public boolean isFinished() {
		return this.cpuTime <= 0;
	} isFinished {
		return this.cpuTime <= 0;
	} return this.cpuTime <= 0; this.cpuTime <= 0 this.cpuTime this this.cpuTime 0 class Queue {
	private LinkedList<Process> queue;
	public Queue() {
		queue = new LinkedList<Process>();
	}
	public void enqueue(Process p) {
		queue.addLast(p);
	}
	public Process dequeue() {
		Process ret = queue.getFirst();
		queue.removeFirst();
		return ret;
	}
	public boolean isEmpty() {
		return queue.size() <= 0;
	}
} Queue private LinkedList<Process> queue; queue public Queue() {
		queue = new LinkedList<Process>();
	} Queue {
		queue = new LinkedList<Process>();
	} queue = new LinkedList<Process>() queue new LinkedList<Process>() public void enqueue(Process p) {
		queue.addLast(p);
	} enqueue {
		queue.addLast(p);
	} queue.addLast(p) queue.addLast queue p Process p p public Process dequeue() {
		Process ret = queue.getFirst();
		queue.removeFirst();
		return ret;
	} dequeue {
		Process ret = queue.getFirst();
		queue.removeFirst();
		return ret;
	} Process ret = queue.getFirst(); ret queue.getFirst() queue.getFirst queue queue.removeFirst() queue.removeFirst queue return ret; ret public boolean isEmpty() {
		return queue.size() <= 0;
	} isEmpty {
		return queue.size() <= 0;
	} return queue.size() <= 0; queue.size() <= 0 queue.size() queue.size queue 0 public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	}
} Main
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	}
}

class Process {
	private String name;
	private int cpuTime;
	public Process(String name, int cpuTime) {
		this.name = name;
		this.cpuTime = cpuTime;
	}
	public String getName() {
		return name;
	}
	public int getCpuTime() {
		return cpuTime;
	}
	public void setCpuTime(int cpuTime) {
		this.cpuTime = cpuTime;
	}
	public boolean isFinished() {
		return this.cpuTime <= 0;
	}
}

class Queue {
	private LinkedList<Process> queue;
	public Queue() {
		queue = new LinkedList<Process>();
	}
	public void enqueue(Process p) {
		queue.addLast(p);
	}
	public Process dequeue() {
		Process ret = queue.getFirst();
		queue.removeFirst();
		return ret;
	}
	public boolean isEmpty() {
		return queue.size() <= 0;
	}
}